Many-to-many: filtering on contains() should use an OUTER JOIN

Issue #2231 resolved
Former user created an issue

See attached test case; without the OUTER JOIN, the query gives wrong results if one of the secondary tables is empty. Tested with 0.6.6 and 0.7.0.

Comments (1)

  1. Mike Bayer repo owner

    I will agree this is an unfortunate caveat of the contains() operator, which has only simple behavior for simple situations. This behavior, including exactly that many-to-many with OR may require outer joins, is fully documented on the site, see http://www.sqlalchemy.org/docs/orm/internals.html?highlight=contains#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains , as well as workarounds.

    I would propose that contains() emit some kind of subquery but then that's exactly what any() already does.

  2. Log in to comment