as other helper methods.
that of regular relations. if passive_deletes flag (also just added)
is not set, a delete of the parent item will trigger a full load of
the child items so that they can be deleted or updated accordingly.
+
+ - also with dynamic, implemented correct count() behavior as well
+ as other helper methods.
- query.get() and query.load() do not take existing filter or other
criterion into account; these methods *always* look up the given id
return None
else:
return sess
-
+
+ def _get_session(self):
+ return self.__session()
+ session = property(_get_session)
+
def __iter__(self):
sess = self.__session()
if sess is None:
return self.attr.get_history(self.state, passive=True)._added_items.__getitem__(index)
else:
return self._clone(sess).__getitem__(index)
-
+
+ def count(self):
+ sess = self.__session()
+ if sess is None:
+ return len(self.attr.get_history(self.state, passive=True)._added_items)
+ else:
+ return self._clone(sess).count()
+
def _clone(self, sess=None):
# note we're returning an entirely new Query class instance here
# without any assignment capabilities;
assert [User(id=7, addresses=[Address(id=1, email_address='jack@bean.com')])] == q.filter(User.id==7).all()
assert fixtures.user_address_result == q.all()
+ def test_count(self):
+ mapper(User, users, properties={
+ 'addresses':dynamic_loader(mapper(Address, addresses))
+ })
+ sess = create_session()
+ u = sess.query(User).first()
+ assert u.addresses.count() == 1, u.addresses.count()
+
def test_backref(self):
mapper(Address, addresses, properties={
'user':relation(User, backref=backref('addresses', lazy='dynamic'))