On Jan 24, 2011, at 5:54 AM, Joel Zhou wrote: > Hi list, > > I defined two tables, Users, Orders and Items, where Orders has a > foreign key "user_id" depending on User.id and Items has a foreign key > "order_id" on Order.id. I'd like to do eager loading when joining > these three tables by: > > session.query(Users).join(Users.orders, > Orders.items).options(contains_eager(User.orders, Orders.items)).all() > > However it turns out that it is still doing lazy loading, not eager > loading. > > Am I doing something wrong?
yes you need contains_eager() for both paths, contains_eager(User.orders), contains_eager(User.orders, Orders.items). Though I can see how this might be improved since the use case of contains_eager() on a non-eager parent is almost impossible. I put ticket #2032 against version 0.7.0 to take a look at this. > > Thanks > Joel > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.