This query will get you close to your desired SQL:
q = session.query(ATable)
q = q.filter(
sa.exists(
[1],
((BTable.atable_id == ATable.id)
(CTable.cval.in_([foo, bar]))),
from_obj=orm.join(BTable, CTable)))
Alternatively, you can add sqlalchemy.orm.relations (ATAble.btables
and BTable.ctables) to your classes and use:
q = session.query(ATable)
q = q.filter(ATable.btables.any(BTable.ctable.has(CTable.cval.in_
([foo, bar]
This will generate another EXISTS clause instead of the join between
BTable and CTable, but in this case they are functionally the same.
The first query will usually be a bit faster.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---