summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-09 11:52:21 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-09 11:52:21 -0400
commitdf4e59ff557b16202c4c3e47ad48667ba1e143c0 (patch)
tree54c32f2a3023a6bd943a5fd1d736daafca338cc9 /lib/sqlalchemy
parent6bdd3bb93fd18a4aec54ee2a836875a922dcaab3 (diff)
downloadsqlalchemy-df4e59ff557b16202c4c3e47ad48667ba1e143c0.tar.gz
Fixed bug when a query of the form:
``query(SubClass).options(subqueryload(Baseclass.attrname))``, where ``SubClass`` is a joined inh of ``BaseClass``, would fail to apply the ``JOIN`` inside the subquery on the attribute load, producing a cartesian product. The populated results still tended to be correct as additional rows are just ignored, so this issue may be present as a performance degradation in applications that are otherwise working correctly. [ticket:2699]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/strategies.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index 5c79de749..e08bb40cb 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -719,7 +719,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
# produce a subquery from it.
left_alias = self._generate_from_original_query(
orig_query, leftmost_mapper,
- leftmost_attr
+ leftmost_attr, entity.mapper
)
# generate another Query that will join the
@@ -772,7 +772,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
def _generate_from_original_query(self,
orig_query, leftmost_mapper,
- leftmost_attr
+ leftmost_attr, entity_mapper
):
# reformat the original query
# to look only for significant columns
@@ -781,6 +781,8 @@ class SubqueryLoader(AbstractRelationshipLoader):
# TODO: why does polymporphic etc. require hardcoding
# into _adapt_col_list ? Does query.add_columns(...) work
# with polymorphic loading ?
+ if entity_mapper.isa(leftmost_mapper):
+ q._set_select_from(entity_mapper)
q._set_entities(q._adapt_col_list(leftmost_attr))
if q._order_by is False:
@@ -792,6 +794,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
# the original query now becomes a subquery
# which we'll join onto.
+
embed_q = q.with_labels().subquery()
left_alias = orm_util.AliasedClass(leftmost_mapper, embed_q,
use_mapper_path=True)