Can't use multiple filters in a query with relation.contains()

Issue #1058 resolved
Former user created an issue

If Bar has a many-to-many relation on Foo then Bar.query.filter(Bar.foos.contains(foo1)).filter(Bar.foos.contains(foo2))

does not currently work. In other words, contains() can be used to check if a relation contains a single specific element, but cannot be used to determine if it contains multiple specific elements.

The reason is that each contains() uses the same secondary table so an alias is needed, but right now no aliasing happens.

It works if we do "not_(...Contains(...))" instead of just "...Contains(...))" because each negated contains() generates a separate subquery.

Comments (4)

  1. Log in to comment