-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backref versus back_populates #46
Comments
I tried to change it, but there is a cyclic dependency between |
Not a big deal. Thanks for trying it out! |
Sorry to comment on an old, closed issue, but this shows up on the first page of google results when you search "backref vs back_populates".
SQLAlchemy's documentation shows using strings for the table references in relationships for this reason. You would always end up with circular imports if you had to import related classes. I personally consider http://docs.sqlalchemy.org/en/latest/orm/basic_relationships.html#one-to-many |
We currently use a
backref
in thedocument
relationship set onDocumentVersion
. Thatbackref
creates a (view-only) relationshipversions
onDocument
, which makes sense.At pyconfr I attended an SQLAlchemy talk where the presenter recommended to use
back_populates
instead ofbackref
.back_populates
has the same meaning asbackref
, except that the complementing relationship property is not created automatically. So usingback_populates
makes the model code more explicit, with no hidden/implicit properties.See the relationship-backref documentation for more information.
This is a minor thing, but I thought I could mention it here :)
The text was updated successfully, but these errors were encountered: