- slight tweak to raw execute() change to also support tuples
for positional parameters, not just lists [ticket:523]
- orm:
+ - fixed critical issue when, after options(eagerload()) is used,
+ the mapper would then always apply query "wrapping" behavior
+ for all subsequent LIMIT/OFFSET/DISTINCT queries, even if no
+ eager loading was applied on those subsequent queries.
- added query.with_parent(someinstance) method. searches for
target instance using lazy join criterion from parent instance.
takes optional string "property" to isolate the desired relation.
except KeyError:
# cache the located strategy per class for faster re-lookup
strategy = cls(self)
- strategy.init()
strategy.is_default = False
+ strategy.init()
self._all_strategies[cls] = strategy
return strategy
def init(self):
self.parent = self.parent_property.parent
self.key = self.parent_property.key
-
+
def init_class_attribute(self):
pass
"to child class '%s': Cant use eager loading on a self "
"referential relationship." %
(self.key, repr(self.parent.class_), repr(self.mapper.class_)))
- self.parent._eager_loaders.add(self.parent_property)
+ if self.is_default:
+ self.parent._eager_loaders.add(self.parent_property)
self.clauses = {}
self.clauses_by_lead_mapper = {}
assert len(u.addresses) == 3
self.assert_sql_count(db, go, 0)
+ sess.clear()
+
+ # test that eager loading doesnt modify parent mapper
+ def go():
+ u = sess.query(User).get_by(user_id=8)
+ assert u.user_id == 8
+ assert len(u.addresses) == 3
+ assert "tbl_row_count" not in self.capture_sql(db, go)
+
def testlazyoptionswithlimit(self):
sess = create_session()
mapper(User, users, properties = dict(
finally:
self.assert_(testdata.sql_count == count, "desired statement count %d does not match %d" % (count, testdata.sql_count))
+ def capture_sql(self, db, callable_):
+ global testdata
+ testdata = TestData(db)
+ buffer = StringIO.StringIO()
+ testdata.buffer = buffer
+ try:
+ callable_()
+ return buffer.getvalue()
+ finally:
+ testdata.buffer = None
+
class ORMTest(AssertMixin):
keep_mappers = False
keep_data = False
self.logger = engine.logger
self.set_assert_list(None, None)
self.sql_count = 0
+ self.buffer = None
def set_assert_list(self, unittest, list):
self.unittest = unittest
ctx = self.ctx
statement = unicode(ctx.compiled)
statement = re.sub(r'\n', '', ctx.statement)
+ if testdata.buffer is not None:
+ testdata.buffer.write(statement + "\n")
if testdata.assert_list is not None:
item = testdata.assert_list[-1]