feat: fix polymorphic relationship descriptors and add test coverage#70
Open
tmgbedu wants to merge 7 commits into
Open
feat: fix polymorphic relationship descriptors and add test coverage#70tmgbedu wants to merge 7 commits into
tmgbedu wants to merge 7 commits into
Conversation
…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>
tmgbedu
force-pushed
the
feat/orm-relationship-fixes-and-tests
branch
from
May 28, 2026 22:28
27dc66c to
f8904f9
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
tmgbedu
force-pushed
the
feat/orm-relationship-fixes-and-tests
branch
from
May 28, 2026 22:29
f8904f9 to
b62a524
Compare
Cover the abstract BaseRelationship contract independent of the concrete relationship query wiring: non-string name rejection, key/attribute defaults, __set_name__ owner recording, __get__ descriptor caching, get_builder registry resolution, __getattr__ builder delegation, joins() clause building, and NotImplementedError for all 11 abstract hooks.
…kfill-1234 # Conflicts: # fastapi_startkit/src/fastapi_startkit/masoniteorm/models/model.py
The polymorphic relationships targeted a stale Model API that later drift removed: get_primary_key_value(), get_primary_key(), and a non-existent .builder property (all silently swallowed to None by Model.__getattr__), and MorphOne/MorphToMany resolved morph_map() via an undefined load_config(). Rewire them against the current API: - morph_map() -> Registry.get_morph_map(); drop load_config - primary key via get_attribute(__primary_key__) / __primary_key__ - resolve the related builder through the registry/factory instead of .builder - get_record_key_lookup() returns the explicit morph alias and raises for models that only carry an auto-registered class-name entry - get_related() is async and no longer awaits a non-awaitable on no match Closes the source bugs tracked in #741 and completes the MorphOne/MorphToMany registry migration tracked in #883. All 25 sqlite morph tests pass.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
__get__descriptor inMorphMany,MorphOne, andMorphToManyto returnselfon class-level access (instance is None), preventingAttributeErroron class-attribute accessmorph_map()inMorphOneandMorphToManyto useregistry.Registry.get_morph_map()instead of the brokenload_config().DB._morph_mapget_record_key_lookupto useRegistry._reverse_mapfor correct alias resolution (previously iterated the forward map in insertion order, finding auto-registered class names before explicit aliases)apply_queryinMorphMany/MorphOneto pass the model instance toget_record_key_lookup, not the builder's model classdelete_attribute()toAttributefor cleaning up transient pivot columns after eager loadingtable()andwithout_global_scopes()helpers toQueryBuilderBelongsToMany,MorphMany,MorphOne, andMorphToManyTest plan
uv run pytest tests/masoniteorm/sqlite/relationships/ -v— all relationship tests passuv run pytest --ignore=tests/masoniteorm/postgres -v— full suite passes without regressions🤖 Generated with Claude Code