use the aliased construct: balias = aliased(B, sq) sess.query(A, balias).outerjoin((balias, balias.foo==A.foo))
On Jan 15, 2009, at 1:22 PM, Roman Kagan wrote: > > > Hi, > > Skimming through the docs I can't figure out how to do the following > (in > SA 0.5): > > Let's have classes A, B, C, D mapped to their respective tables. > > I do > > sq = sess.query(B, C.foo).join(C).join(D).filter(D.bar == > smth).subquery() > q = sess.query(A).outerjoin((sq, sq.c.foo == A.foo)) > > Now q contains A's. > > How can I make q also contain B's (for the rows where B is present)? > > q.add_entity(B) doesn't give the right answer because it adds B table > into the FROM clause in SQL which results in the cartesian product > of A > and B tables outerjoined with the subquery. > > I'm out of ideas, any help is appreciated. > > Thanks, > Roman. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
