On Thu, Feb 25, 2016 at 7:53 AM, 尤立宇 <afg...@gmail.com> wrote: > Thanks for your response. > > Do you consider using `backref` only on one of the class bad practice? > > I'm curious because automatically creating descriptors seems possible to > me, and I'm wondering when it happens. > > As documentation states so: > > Remember, when the backref keyword is used on a single relationship, it’s > exactly the same as if the above two relationships were created > individually using back_populates on each. > > ref: http://docs.sqlalchemy.org/en/latest/orm/backref.html > > There is also a half-a-year-old stackoverflow question about it: > > > http://stackoverflow.com/questions/32617371/how-to-force-creation-of-backref-instrumentedattributes-using-sqlalchemy > > > I think it's a matter of personal preference. Some people like to see all the attributes of a class defined as part of the class definition itself, in which case they'll need to use 2 relationship definitions with the back_populates argument. Others prefer a terser syntax with less duplication, so they use the backref argument.
If you want to trigger the creation of all "pending" backref attributes, I think you can call sqlalchemy.orm.configure_mappers: http://docs.sqlalchemy.org/en/rel_1_0/orm/mapping_api.html#sqlalchemy.orm.configure_mappers Normally this gets called automatically when you start querying the database, but in certain instances you may want to call it explicitly. Simon -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.