convenient than using dynamic relations in some cases; for those who
have not, you might notice your apps using a lot fewer queries than
before in some situations. [ticket:871]
-
+
+ - query.get() and query.load() do not take existing filter or other
+ criterion into account; these methods *always* look up the given id
+ in the database or return the current instance from the identity map,
+ disregarding any existing filter, join, group_by or other criterion
+ which has been configured. [ticket:893]
+
- new synonym() behavior: an attribute will be placed on the mapped
class, if one does not exist already, in all cases. if a property
already exists on the class, the synonym will decorate the property
self._primary_adapter=None
self._only_load_props = None
self._refresh_instance = None
+
+ def _no_criterion(self):
+ q = self._clone()
+ q._from_obj = [self.table]
+ q._alias_ids = {}
+ q._joinpoint = self.mapper
+ q._statement = q._aliases = q._criterion = None
+ q._order_by = q._group_by = q._distinct = False
+ return q
def _clone(self):
q = Query.__new__(Query)
ident = util.to_list(ident)
q = self
-
if ident is not None:
+ q = q._no_criterion()
params = {}
(_get_clause, _get_params) = self.select_mapper._get_clause
q = q.filter(_get_clause)
s.clear()
u2 = s.query(User).get(7)
assert u is not u2
+
+ def test_no_criterion(self):
+ """test that get()/load() does not use preexisting filter/etc. criterion"""
+
+ s = create_session()
+
+ assert s.query(User).filter(User.id==7).get(19) is None
+
+ u = s.query(User).get(7)
+ assert s.query(User).filter(User.id==9).get(7) is u
+ s.clear()
+ assert s.query(User).filter(User.id==9).get(7).id == u.id
+ # user 10 has no addresses
+ u = s.query(User).get(10)
+ assert s.query(User).join('addresses').get(10) is u
+ s.clear()
+ assert s.query(User).join('addresses').get(10).id == u.id
+
+ u = s.query(User).get(7)
+ assert s.query(User).join('addresses').filter(Address.user_id==8).filter(User.id==7).first() is None
+ assert s.query(User).join('addresses').filter(Address.user_id==8).get(7) is u
+ s.clear()
+ assert s.query(User).join('addresses').filter(Address.user_id==8).get(7).id == u.id
+
+ assert s.query(User).join('addresses').filter(Address.user_id==8).load(7).id == u.id
+
def test_unique_param_names(self):
class SomeUser(object):
pass