summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-06-30 20:25:04 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-06-30 20:25:04 -0400
commit2d8d1dcf60e023275b8dcfea015ec16cad69d266 (patch)
tree3a53a49ffaf72a955af4c1005888b76c3f9f6c8b /lib
parent4b6d6d5f8024e2192c4383a0c4a3dd459900ff1a (diff)
downloadsqlalchemy-2d8d1dcf60e023275b8dcfea015ec16cad69d266.tar.gz
- repair the _enable_single_crit method, it was named the same
as the attribute and probably just replaced itself, so that is now _set_enable_single_crit - as a side effect of the main issue fixed here, correct the case in adjust_for_single_inheritance where the same mapper appears more than once in mapper_adapter_map; run through a set() for uniqueness. - Fixed bug in subquery eager loading in conjunction with :func:`.with_polymorphic`, the targeting of entities and columns in the subquery load has been made more accurate with respect to this type of entity and others. Fixes #3106
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/orm/query.py7
-rw-r--r--lib/sqlalchemy/orm/strategies.py20
2 files changed, 14 insertions, 13 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 5d60c4e29..728f7787a 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -941,7 +941,7 @@ class Query(object):
"""
fromclause = self.with_labels().enable_eagerloads(False).\
- _enable_single_crit(False).\
+ _set_enable_single_crit(False).\
statement.correlate(None)
q = self._from_selectable(fromclause)
if entities:
@@ -949,7 +949,7 @@ class Query(object):
return q
@_generative()
- def _enable_single_crit(self, val):
+ def _set_enable_single_crit(self, val):
self._enable_single_crit = val
@_generative()
@@ -2908,7 +2908,8 @@ class Query(object):
subtypes are selected from the total results.
"""
- for (ext_info, adapter) in self._mapper_adapter_map.values():
+
+ for (ext_info, adapter) in set(self._mapper_adapter_map.values()):
if ext_info in self._join_entities:
continue
single_crit = ext_info.mapper._single_table_criterion
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index 567c09fff..81860e045 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -713,7 +713,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
elif subq_path.contains_mapper(self.mapper):
return
- subq_mapper, leftmost_mapper, leftmost_attr, leftmost_relationship = \
+ leftmost_mapper, leftmost_attr, leftmost_relationship = \
self._get_leftmost(subq_path)
orig_query = context.attributes.get(
@@ -725,7 +725,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
left_alias = self._generate_from_original_query(
orig_query, leftmost_mapper,
leftmost_attr, leftmost_relationship,
- entity.mapper
+ entity.entity_zero
)
# generate another Query that will join the
@@ -738,13 +738,12 @@ class SubqueryLoader(AbstractRelationshipLoader):
("orig_query", SubqueryLoader): orig_query,
('subquery_path', None): subq_path
}
- q = q._enable_single_crit(False)
+ q = q._set_enable_single_crit(False)
to_join, local_attr, parent_alias = \
self._prep_for_joins(left_alias, subq_path)
q = q.order_by(*local_attr)
q = q.add_columns(*local_attr)
-
q = self._apply_joins(q, to_join, left_alias,
parent_alias, effective_entity)
@@ -771,15 +770,17 @@ class SubqueryLoader(AbstractRelationshipLoader):
leftmost_cols = leftmost_prop.local_columns
leftmost_attr = [
- leftmost_mapper._columntoproperty[c].class_attribute
+ getattr(subq_path[0].entity,
+ leftmost_mapper._columntoproperty[c].key)
for c in leftmost_cols
]
- return subq_mapper, leftmost_mapper, leftmost_attr, leftmost_prop
+
+ return leftmost_mapper, leftmost_attr, leftmost_prop
def _generate_from_original_query(self,
orig_query, leftmost_mapper,
leftmost_attr, leftmost_relationship,
- entity_mapper
+ orig_entity
):
# reformat the original query
# to look only for significant columns
@@ -787,9 +788,8 @@ class SubqueryLoader(AbstractRelationshipLoader):
# set a real "from" if not present, as this is more
# accurate than just going off of the column expression
- if not q._from_obj and entity_mapper.isa(leftmost_mapper):
- q._set_select_from([entity_mapper], False)
-
+ if not q._from_obj and orig_entity.mapper.isa(leftmost_mapper):
+ q._set_select_from([orig_entity], False)
target_cols = q._adapt_col_list(leftmost_attr)
# select from the identity columns of the outer