]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
a few tweaks and the polymorph example can also use eager loading
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 20 Mar 2006 01:16:16 +0000 (01:16 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 20 Mar 2006 01:16:16 +0000 (01:16 +0000)
examples/polymorph/polymorph.py
lib/sqlalchemy/mapping/properties.py
lib/sqlalchemy/sql.py

index d240a55ac3777794831636f211407b9638dc5f09..804ef4e7a30e488fd0f3d83cc92622fac0339826 100644 (file)
@@ -71,7 +71,7 @@ person_join = select(
             select(
             [people, engineers.c.description, column("'engineer'").label('type')],
             people.c.person_id==engineers.c.person_id)).alias('pjoin')
-
+            
 
 # lets print out what this Selectable looks like.  The mapper is going to take the selectable and
 # Select off of it, with the flag "use_labels" which indicates to prefix column names with the table
@@ -106,7 +106,7 @@ people_mapper = mapper(Person, person_join, extension=ext)
 # (translation: it'll work)
 # TODO: get the eager loading to work (the compound select alias doesnt like being aliased itself)
 assign_mapper(Company, companies, properties={
-    'employees': relation(people_mapper, private=True)
+    'employees': relation(people_mapper, lazy=False, private=True)
 })
 
 c = Company(name='company1')
index 6b8c137930c5d7e0061408a6b8ad693203adde00..6a073f0a6bdc7d0891ab0fe3151b8e538a71d1f7 100644 (file)
@@ -785,10 +785,18 @@ class EagerLoader(PropertyLoader):
 
     def _instance(self, row, imap, result_list=None):
         """gets an instance from a row, via this EagerLoader's mapper."""
+        # since the EagerLoader makes an Alias of its mapper's table,
+        # we translate the actual result columns back to what they 
+        # would normally be into a "virtual row" which is passed to the child mapper.
+        # that way the mapper doesnt have to know about the modified column name
+        # (neither do any MapperExtensions).  The row is keyed off the Column object
+        # (which is what mappers use) as well as its "label" (which might be what
+        # user-defined code is using)
         fakerow = util.DictDecorator(row)
         for c in self.eagertarget.c:
             parent = self.target._get_col_by_original(c.original)
             fakerow[parent] = row[c]
+            fakerow[parent._label] = row[c]
         row = fakerow
         return self.mapper._instance(row, imap, result_list)
 
index b88cf18cd04154475474c462661b74ed3d8ecfec..e87fd3443b7134953ba12a9182c478dde6b541e6 100644 (file)
@@ -1040,6 +1040,7 @@ class ColumnClause(ColumnElement):
             return BindParamClause(self.table.name + "_" + self.text, obj, shortname = self.text, type=self.type)
     def _make_proxy(self, selectable, name = None):
         c = ColumnClause(name or self.text, selectable)
+        c._original = self.original
         selectable.columns[c.name] = c
         return c
     def _compare_type(self, obj):