Conversation
Standardize collection relationships on Relation[list[T]] with Field-backed BackRef and ManyToMany helpers. Made-with: Cursor
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.
Description
Redesigns collection relationship declarations so type annotations describe the lazy runtime relationship handle while
Field(...)metadata declares relationship behavior. This resolves the BackRef typing issues behind #28 and gives many-to-many relationships the same Field-backed helper pattern.Closes #28
Changes
Relation[list[T]]for lazy collection relationship handles and move collection query typing there.BackRef()andManyToMany(...)into public helpers overField(back_ref=True)andField(many_to_many=True, related_name=..., through=...).Field(...)metadata as the source of truth, with migration errors for oldBackRef[...]andManyToManyField(...)patterns.Bridge and Schema Impact
src/ferro/_core.pyiupdated (if needed)Migration / Breaking Changes
Old collection declarations now need to migrate:
posts: BackRef[list[Post]] | None = None->posts: Relation[list[Post]] = BackRef()courses: Annotated[list[Course], ManyToManyField(...)] = None->courses: Relation[list[Course]] = ManyToMany(...)Singular reverse relationships continue to use the existing awaitable behavior, e.g.
profile: "Profile" = BackRef().Documentation and Changelog
Related Issues
Closes #28
Test plan
uv run pytest -qcargo testuv run ruff check <changed code/test files>uv run ruff format --check <changed code/test files>Note:
uv run mkdocs build --strictstill fails on existing strict-doc warnings unrelated to this PR (api/fields.mdmissing crossrefs, existing guide anchors, and untyped**fieldsdoc warnings).Made with Cursor