Query to check if size of collection is 0 or empty in SQLAlchemy?
Use negation (~
) with any
:
q = session.query(Person)
q = q.filter(Person.building == g.current_building)
q = q.filter(~Person.groups.any())
any
is more powerful than needed in your case, but it will do the job just fine.