summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-09-28 05:26:26 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-09-28 05:26:26 +0000
commit7a6e6711996cfc08fdb38d766bac464d1a33e5a9 (patch)
tree389e9299ffba0b555bd8b2cdf736bf5fcdc78b22 /lib/sqlalchemy
parent35fe9f7b588e8956fec069e72b9bd81ffa455423 (diff)
downloadsqlalchemy-7a6e6711996cfc08fdb38d766bac464d1a33e5a9.tar.gz
- more adjustments to the eager load table finder to work with existing mappings
against selects and query-created limit/offset subselects - added eagertest3 to orm/alltests.py
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/properties.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py
index db34a9a2a..6e9f9daff 100644
--- a/lib/sqlalchemy/orm/properties.py
+++ b/lib/sqlalchemy/orm/properties.py
@@ -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)