python - In SQLAlchemy, can you filter a polymorphically associated model by the type of its associated record? -
i'm using polymorphic association in sqlalchemy described in this example. can found in examples directory in sqlalchemy source code.
given setup, want query address
es associated user
s. not a user
any user
.
in raw sql, this:
select addresses.* addresses join address_associations on addresses.assoc_id = address_associations.assoc_id address_associations.type = 'user'
is there way using orm session?
could run raw sql , apply address class each row in results?
ad-hoc joins using orm described at:
http://www.sqlalchemy.org/docs/orm/tutorial.html#querying-with-joins
for address in sess.query(address).join(address.association).filter_by(type='users'): print "street", address.street, "member", address.member
Comments
Post a Comment