Skip to content

feat: fix polymorphic relationship descriptors and add test coverage#70

Open
bedus-creation wants to merge 3 commits into
mainfrom
feat/orm-relationship-fixes-and-tests
Open

feat: fix polymorphic relationship descriptors and add test coverage#70
bedus-creation wants to merge 3 commits into
mainfrom
feat/orm-relationship-fixes-and-tests

Conversation

@bedus-creation

Copy link
Copy Markdown
Contributor

Summary

  • Fix __get__ descriptor in MorphMany, MorphOne, and MorphToMany to return self on class-level access (instance is None), preventing AttributeError on class-attribute access
  • Fix morph_map() in MorphOne and MorphToMany to use registry.Registry.get_morph_map() instead of the broken load_config().DB._morph_map
  • Fix get_record_key_lookup to use Registry._reverse_map for correct alias resolution (previously iterated the forward map in insertion order, finding auto-registered class names before explicit aliases)
  • Fix apply_query in MorphMany/MorphOne to pass the model instance to get_record_key_lookup, not the builder's model class
  • Add delete_attribute() to Attribute for cleaning up transient pivot columns after eager loading
  • Add table() and without_global_scopes() helpers to QueryBuilder
  • Add full test suites for BelongsToMany, MorphMany, MorphOne, and MorphToMany

Test plan

  • uv run pytest tests/masoniteorm/sqlite/relationships/ -v — all relationship tests pass
  • uv run pytest --ignore=tests/masoniteorm/postgres -v — full suite passes without regressions

🤖 Generated with Claude Code

bedus-creation and others added 2 commits May 28, 2026 13:18
…est coverage

- Add `if instance is None: return self` guard to MorphMany, MorphOne, MorphToMany __get__
- Fix morph_map() to use registry.Registry.get_morph_map() instead of broken load_config().DB._morph_map
- Fix get_record_key_lookup to use Registry._reverse_map for O(1) lookup and correct alias resolution
- Fix apply_query in MorphMany/MorphOne to pass the model instance (not the builder's class) to get_record_key_lookup
- Add delete_attribute() helper to Attribute for cleaning up transient pivot attributes
- Add table() and without_global_scopes() helpers to QueryBuilder
- Add tests for BelongsToMany, MorphMany, MorphOne, and MorphToMany relationships

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bedus-creation bedus-creation force-pushed the feat/orm-relationship-fixes-and-tests branch from 27dc66c to f8904f9 Compare May 28, 2026 22:28
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bedus-creation bedus-creation force-pushed the feat/orm-relationship-fixes-and-tests branch from f8904f9 to b62a524 Compare May 28, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant