- implemented foreign_keys argument to mapper [ticket:385]. use in conjunction with
primaryjoin/secondaryjoin arguments to specify/override foreign keys defined on the
Table instance.
+ - extension() query option propigates to Mapper._instance() method so that
+ all loading-related methods get called [ticket:454]
- eager relation to an inheriting mapper wont fail if no rows returned for
the relationship.
- fix for very large topological sorts, courtesy ants.aasma at gmail [ticket:423]
if not context.identity_map.has_key(identitykey):
context.identity_map[identitykey] = instance
isnew = True
- if self.extension.populate_instance(self, context, row, instance, identitykey, isnew) is EXT_PASS:
+ if context.extension.populate_instance(self, context, row, instance, identitykey, isnew) is EXT_PASS:
self.populate_instance(context, instance, row, identitykey, isnew)
- if self.extension.append_result(self, context, row, instance, identitykey, result, isnew) is EXT_PASS:
+ if context.extension.append_result(self, context, row, instance, identitykey, result, isnew) is EXT_PASS:
if result is not None:
result.append(instance)
return instance
return None
# plugin point
- instance = self.extension.create_instance(self, context, row, self.class_)
+ instance = context.extension.create_instance(self, context, row, self.class_)
if instance is EXT_PASS:
instance = self._create_instance(context.session)
else:
# call further mapper properties on the row, to pull further
# instances from the row and possibly populate this item.
- if self.extension.populate_instance(self, context, row, instance, identitykey, isnew) is EXT_PASS:
+ if context.extension.populate_instance(self, context, row, instance, identitykey, isnew) is EXT_PASS:
self.populate_instance(context, instance, row, identitykey, isnew)
- if self.extension.append_result(self, context, row, instance, identitykey, result, isnew) is EXT_PASS:
+ if context.extension.append_result(self, context, row, instance, identitykey, result, isnew) is EXT_PASS:
if result is not None:
result.append(instance)
return instance
session = self.session
- context = SelectionContext(self.select_mapper, session, with_options=self.with_options, **kwargs)
+ context = SelectionContext(self.select_mapper, session, self.extension, with_options=self.with_options, **kwargs)
result = util.UniqueAppender([])
if mappers:
to the freshly loaded value
"""
- def __init__(self, mapper, session, **kwargs):
+ def __init__(self, mapper, session, extension, **kwargs):
self.populate_existing = kwargs.pop('populate_existing', False)
self.version_check = kwargs.pop('version_check', False)
self.session = session
+ self.extension = extension
self.identity_map = {}
super(SelectionContext, self).__init__(mapper, kwargs.pop('with_options', []), **kwargs)
def accept_option(self, opt):
def testextensionoptions(self):
sess = create_session()
- mapper(User, users)
+ class ext1(MapperExtension):
+ def populate_instance(self, mapper, selectcontext, row, instance, identitykey, isnew):
+ """test options at the Mapper._instance level"""
+ instance.TEST = "hello world"
+ return EXT_PASS
+ mapper(User, users, extension=ext1())
class testext(MapperExtension):
def select_by(self, *args, **kwargs):
+ """test options at the Query level"""
return "HI"
+ def populate_instance(self, mapper, selectcontext, row, instance, identitykey, isnew):
+ """test options at the Mapper._instance level"""
+ instance.TEST_2 = "also hello world"
+ return EXT_PASS
l = sess.query(User).options(extension(testext())).select_by(x=5)
assert l == "HI"
+ l = sess.query(User).options(extension(testext())).get(7)
+ assert l.user_id == 7
+ assert l.TEST == "hello world"
+ assert l.TEST_2 == "also hello world"
def testeageroptions(self):
"""tests that a lazy relation can be upgraded to an eager relation via the options method"""