David Gardner wrote: > I'm having a bit of a problem eager loading the parent node of a > hierarchical tree-like table (ie, every node has one to many children). > If I simply add a "options(eagerload(Asset.Parent))" to my query it > works as expected. > > However often I need to select a node based on it's attributes as well > as the parent's attributes, so do a > "join(Asset.Parent).options(contains_eager(Asset.Parent))"
if this is a self referential join, you have to alias the target you're joining to. usually the aliased=True flag would be sufficient for the join(), but since you want to contains_eager() it as well, this all must be laid out explicitly: parent = aliased(Asset) query.join((parent, Asset.parent)).options(contains_eager(Asset.parent, alias=parent)) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---