refactor(relations): rename BackRelationship to BackRef and add Field(back_ref=True)#4
Merged
refactor(relations): rename BackRelationship to BackRef and add Field(back_ref=True)#4
Conversation
- Updated references from BackRelationship to BackRef across the codebase for consistency. - Added new parameters (primary_key, autoincrement, unique, index, back_ref) to the Field function to enhance field definition capabilities. - Improved back-reference handling in the metaclass to prevent conflicts between BackRef and Field(back_ref=True).
- Replaced instances of BackRelationship with BackRef in the documentation for clarity. - Added back_ref parameter to Field documentation to improve understanding of reverse relationships. - Updated examples to reflect the new usage of BackRef and Field(back_ref=True). - Enhanced CSS to prevent parameter table columns from wrapping for better readability.
- Replaced all instances of BackRelationship with BackRef in the test suite for consistency with recent refactoring. - Adjusted related test assertions to reflect the new BackRef usage. - Added new tests to validate the behavior of back references using Field(back_ref=True) in various scenarios.
- Replaced instances of BackRelationship with BackRef in demo_queries.py for consistency with recent refactoring. - Adjusted the products and actors fields in the Category and Movie models to reflect the new BackRef usage.
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
Renames the reverse-relationship marker from
BackRelationshiptoBackRefand adds an alternative way to declare back-refs viaField(back_ref=True), so users can keep a plain type likelist["Post"] | Nonewhile still marking the field as a reverse relation. The shorter name and optionalback_refflag improve ergonomics and type clarity.Changes
BackRelationshiptoBackRefacross the codebase (query builder, public API, metaclass, relations resolution, tests, demo, docs).back_ref: booltoField(); reorder Ferro-specific params (primary_key, autoincrement, unique, index, back_ref) before Pydantic params in overloads and implementation.BackRef[...]) or viaField(back_ref=True)(default or inAnnotated); raiseTypeErrorif both are used on the same field.Field(back_ref=True)examples), fields (back_ref param table), API reference (query-builder BackRef), and extra.css (parameter table column nowrap).Field(default=None, back_ref=True),Annotated[..., Field(back_ref=True)], and the “both BackRef and back_ref=True” error.Bridge and Schema Impact
src/ferro/_core.pyiupdated (if needed)Migration / Breaking Changes
Impact: Any use of
BackRelationshipmust be updated toBackRef(same semantics). Optional: reverse relations can be declared withField(back_ref=True)and a plain type instead ofBackRef[...].Upgrade: Replace
BackRelationshipwithBackRefin imports and type annotations; no other code changes required for existing back-refs.Documentation and Changelog
Related Issues