On May 6, 2013, at 3:21 PM, V'Raj Kanwade <viraj.kanw...@gmail.com> wrote:
> Hi, > > I have 2 tables: Members & GroupMembers > > orm.mapper(Member, meta.Members) > orm.mapper(GroupMember, meta.GroupMembers > properties={ > 'member': orm.relation(Member, > primaryjoin=meta.GroupMembers.c.memberID == meta.Members.c.id, > lazy=False) > } > ) > > I want to do something like > query = session.query(GroupMember).order_by(GroupMember.member.name) > > I get "AttributeError: Neither 'InstrumentedAttribute' object nor > 'Comparator' object has an attribute 'name'" error. > > I can do something like > query = session.query(GroupMember).join(Member).order_by(Member.name) > but this results in multiple joins on the same table. query(GroupMember).join(Member).order_by(Member.name) is the right answer, and only generates one JOIN. The second join you're seeing is due to your lazy=False, and is a separate concern which cannot be used to impact the query results - see http://docs.sqlalchemy.org/en/rel_0_8/orm/loading.html#the-zen-of-eager-loading for background on this, as well as http://docs.sqlalchemy.org/en/rel_0_8/orm/loading.html#contains-eager which is probably what you'll end up doing. -- 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 http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.