On Apr 7, 2008, at 4:54 PM, Tim Lesher wrote:
> > I'm having some trouble using the has() operator to avoid a long chain > of joins in a select. > > > session > .query(Action).filter(Action.task.has(Connection.caller==caller1)) > > However, this appears to generate a cartesian join on the 'tasks' and > 'connections' in the EXISTS() subselect, which leads to extra actions > being returned. for this kind of thing, you're joining across three tables, so you can put an extra join condition in the has(): filter(Action.task.has(and_(Connection.caller==caller1, Task.connection_id==Connection.id))) or do it with join(): query(Action).join('task').filter(Task.has(Connection.caller==caller1)) I have an intuitive sense that there should be some nice syntax to get has() and any() to join across more tables but its not occuring to me at the moment. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---