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 addresses associated users. 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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -