return a.contains(b)
contains_op = staticmethod(contains_op)
+ def any_op(a, b):
+ return a.any(b)
+ any_op = staticmethod(any_op)
+
def __init__(self, prop):
self.prop = prop
def contains(self, other):
"""return true if this collection contains other"""
return self.operate(PropComparator.contains_op, other)
+
+ def any(self, criterion):
+ """return true if this collection contains any member that meets the given criterion"""
+ return self.operate(PropComparator.any_op, criterion)
class StrategizedProperty(MapperProperty):
"""A MapperProperty which uses selectable strategies to affect
else:
return self.prop._optimized_compare(other)
+ def any(self, criterion):
+ if not self.prop.uselist:
+ raise exceptions.InvalidRequestError("'any' not implemented for scalar attributes")
+ j = self.prop.primaryjoin
+ if self.prop.secondaryjoin:
+ j = j & self.prop.secondaryjoin
+ return sql.exists([1], j & criterion)
+
def contains(self, other):
if not self.prop.uselist:
raise exceptions.InvalidRequestError("'contains' not implemented for scalar attributes")
assert True
#assert [User(id=7), User(id=9), User(id=10)] == sess.query(User).filter(User.addresses!=address).all()
+
+ def test_any(self):
+ sess = create_session()
+ address = sess.query(Address).get(3)
+ assert [User(id=8), User(id=9)] == sess.query(User).filter(User.addresses.any(Address.email_address.like('%ed%'))).all()
def test_contains_m2m(self):
sess = create_session()