python - Querying a many-to-many relationship in SQLAlchemy -
i have pretty standard many-to-many relationship, similar blog -> keyword relationship in orm tutorial.
i query list of keywords, returning blog posts of them match. however, can't work out if there simple way this. if add multiple filters, repeatedly doing
.filter(blog.keywords.any(keyword.name == 'keyword'))
then 'and'/'exists' query, such posts have keywords returned. there simple way 'or' query, or need work using join().
thanks help; can't work out whether missing something.
i think want
.filter(blog.keywords.any(keyword.name.in_(['keyword1', 'keyword2', ...])))
i'm using http://www.sqlalchemy.org/docs/05/ormtutorial.html#common-filter-operators reference
Comments
Post a Comment