I have a many-to-many (developers & projects) relationship modeled using SA\'s association_proxy. The collections (developers on each project & project
To add to Denis's answer:
When I tried the any()
method, I got this error
sqlalchemy.exc.InvalidRequestError: 'any()' not implemented for scalar attributes. Use has().
Using has()
instead of any()
worked for me.
It looks like any()
is for list relationships (in this case Developers potentially have multiple projects so Developer.developerProjects
is a list). Whereas has()
is for a single relationship (for instance if a Developer
had one Workplace
associated).
Here is the link to documentation: http://docs.sqlalchemy.org/en/latest/orm/internals.html#sqlalchemy.orm.properties.RelationshipProperty.Comparator.has
Use any() method of association proxy:
s.query(Developer).filter(Developer.developerProjects.any(status='active'))