The relevant docs say this (
http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#sqlalchemy.orm.relationship.params.backref
)
backref
indicates the string name of a property to be placed on the related
mapper’s class that will handle this relationship in the other direction.
The other property will be created automatically when the mappers are
configured. Can also be passed as a backref() object to control the
configuration of the new relationship.
Using your examples side-by-side:
user = relationship("User", backref=backref('addresses', order_by=id))
addresses = relationship("Address", backref="user")
The first form uses a `sqlalchemy.orm.backref constructor object, which not
only specifies the backref to be 'addresses', but also an order_by. you
might also want to configure many other qualities of the relationship --
this constructor essentially creates a backref by proxying the kwargs to
`sqlalchemy.orm.relationship`
The second form uses a string. It is basically a shorthand that creates a
many-to-many backref without any options.
Which to use is up to you. I often start with a string, and then convert
if/when needed.
The `backref()` form is useful for configuring things like:
• ordering
• specify a "to-one" relationship
• only join on certain conditions
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.