On Feb 15, 2011, at 5:21 PM, Michael Hipp wrote: > This works: > Seller = aliased(Dealer) > Buyer = aliased(Dealer) > q = self.session.query(Car, Seller.name, Buyer.name) > q = q.outerjoin((Car.seller, Seller), (Car.buyer, Buyer)) > > This doesn't: > Seller = aliased(Dealer) > Buyer = aliased(Dealer) > q = self.session.query(Car, Seller.name, Buyer.name) > q = q.outerjoin(Car.seller, Seller) > q = q.outerjoin(Car.buyer, Buyer) > > sqlalchemy.exc.ArgumentError: Can't determine join between 'Join object on > cars(71352432) and dealers(71704656)' and '%(78454064 dealers)s'; tables have > more than one foreign key constraint relationship between them. Please > specify the 'onclause' of this join explicitly. > > Is this by design?
the "target" goes first for "target, onclause", syntax, note this is an 0.7 syntax: q = q.outerjoin(Seller, Car.seller) q = q.outerjoin(Buyer, Car.buyer) in 0.6 you need the tuples for "target, onclause": q = q.outerjoin((Seller, Car.seller)) q = q.outerjoin((Buyer, Car.buyer)) Consult http://www.sqlalchemy.org/docs/orm/tutorial.html#querying-with-joins and http://www.sqlalchemy.org/docs/orm/query.html#sqlalchemy.orm.query.Query.join for reference on this. in this case you are using a property as the "on" which includes the left and right points, so you don't really need the "target", the single-arg form works: q = q.outerjoin(Car.seller) q = q.outerjoin(Car.buyer) the "onclause, target" form is a legacy syntax which is why it still attempts to work. > > Thanks, > Michael > > -- > 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.