summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-03-26 07:21:28 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-03-26 07:21:28 +0000
commitfcace31b887d0edb73dfd01a9134727d3647061f (patch)
tree0b0b69520288d6fc4a3dc8f5faaff04ae3b02ce2 /lib/sqlalchemy
parent69246aec95b9f0c36bea4c8ebcb1062b3738887b (diff)
downloadsqlalchemy-fcace31b887d0edb73dfd01a9134727d3647061f.tar.gz
improved translation of rows when proxying rows from one mapper to another.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/mapping/mapper.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/sqlalchemy/mapping/mapper.py b/lib/sqlalchemy/mapping/mapper.py
index 32da013ac..82257ae62 100644
--- a/lib/sqlalchemy/mapping/mapper.py
+++ b/lib/sqlalchemy/mapping/mapper.py
@@ -854,19 +854,27 @@ class Mapper(object):
# 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, instance, row, identitykey, imap, isnew):
- self.populate_instance(instance, row, identitykey, imap, isnew, translate=False)
+ self.populate_instance(instance, row, identitykey, imap, isnew)
if self.extension.append_result(self, row, imap, result, instance, isnew, populate_existing=populate_existing):
if result is not None:
result.append_nohistory(instance)
return instance
- def populate_instance(self, instance, row, identitykey, imap, isnew, translate=True):
- if translate:
- newrow = {}
- for table in self.tables:
- for c in table.c:
- newrow[c] = row[c.key]
- row = newrow
+ def translate_row(self, tomapper, row):
+ """attempts to take a row and translate its values to a row that can
+ be understood by another mapper. breaks the column references down to their
+ bare keynames to accomplish this. So far this works for the various polymorphic
+ examples."""
+ newrow = util.DictDecorator(row)
+ for c in self.table.c:
+ newrow[c.key] = row[c]
+ for c in tomapper.table.c:
+ newrow[c] = newrow[c.key]
+ return newrow
+
+ def populate_instance(self, instance, row, identitykey, imap, isnew, frommapper=None):
+ if frommapper is not None:
+ row = frommapper.translate_row(self, row)
for prop in self.props.values():
prop.execute(instance, row, identitykey, imap, isnew)