filtering by association attributes with SqlAlchemy association_proxy

后端 未结 2 732
日久生厌
日久生厌 2021-02-05 19:23

I have a many-to-many (developers & projects) relationship modeled using SA\'s association_proxy. The collections (developers on each project & project

2条回答
  •  不要未来只要你来
    2021-02-05 20:08

    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

提交回复
热议问题