]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- more adjustments to the eager load table finder to work with existing mappings
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 28 Sep 2006 05:26:26 +0000 (05:26 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 28 Sep 2006 05:26:26 +0000 (05:26 +0000)
against selects and query-created limit/offset subselects
- added eagertest3 to orm/alltests.py

lib/sqlalchemy/orm/properties.py
test/orm/alltests.py

index db34a9a2abfe2f7e0828bb74bb668d841f19268f..6e9f9daff5b37f1c143440820b3e1174fa79549f 100644 (file)
@@ -599,13 +599,22 @@ class EagerLoader(LazyLoader):
         
         if hasattr(statement, '_outerjoin'):
             towrap = statement._outerjoin
-        else:
+        elif isinstance(self.localparent.mapped_table, schema.Table):
+            # if the mapper is against a plain Table, look in the from_obj of the select statement
+            # to join against whats already there.
             for (fromclause, finder) in [(x, sql_util.TableFinder(x)) for x in statement.froms]:
-                if self.localparent.mapped_table in finder:
+                # dont join against an Alias'ed Select.  we are really looking either for the 
+                # table itself or a Join that contains the table.  this logic still might need
+                # adjustments for scenarios not thought of yet.
+                if not isinstance(fromclause, sql.Alias) and self.localparent.mapped_table in finder:
                     towrap = fromclause
                     break
             else:
-                raise exceptions.InvalidRequestError("EagerLoader cannot locate a clause with which to outer join to, in query '%s'" % str(statement))
+                raise exceptions.InvalidRequestError("EagerLoader cannot locate a clause with which to outer join to, in query '%s' %s" % (str(statement), self.localparent.mapped_table))
+        else:
+            # if the mapper is against a select statement or something, we cant handle that at the
+            # same time as a custom FROM clause right now.
+            towrap = self.localparent.mapped_table
             
         if self.secondaryjoin is not None:
             statement._outerjoin = sql.outerjoin(towrap, self.eagersecondary, self.eagerprimary).outerjoin(self.eagertarget, self.eagersecondaryjoin)
index 814b2d760bfe89f4561e241294919112fbef3f31..7fcac805abf22e02638599021c6e9e61b383ded7 100644 (file)
@@ -7,6 +7,7 @@ def suite():
         'orm.lazytest1',
         'orm.eagertest1',
         'orm.eagertest2',
+        'orm.eagertest3',
         
         'orm.sessioncontext', 
         'orm.unitofwork',