Closed
Description
Migrated issue, originally created by Michael Bayer (@zzzeek)
see zzzeek/sqlalchemy#33 for current work on this.
proposed patch:
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index 6ca737c..23e8cb6 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -767,8 +767,17 @@ class SubqueryLoader(AbstractRelationshipLoader):
if not q._from_obj and entity_mapper.isa(leftmost_mapper):
q._set_select_from([entity_mapper](entity_mapper), False)
+ target_cols = q._adapt_col_list(leftmost_attr)
+
# select from the identity columns of the outer
- q._set_entities(q._adapt_col_list(leftmost_attr))
+ q._set_entities(target_cols)
+
+ # if target_cols refer to a non-primary key or only
+ # part of a composite primary key, set the q as distinct
+ for c in target_cols:
+ if not set(target_cols).issuperset(c.table.primary_key):
+ q._distinct = True
+ break
if q._order_by is False:
q._order_by = leftmost_mapper.order_by
we'll try to backport an "experimental" version of this to 0.8/0.7.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon Oct 13, 2013
Michael Bayer (@zzzeek) wrote:
f00544a master
28a3491 0.8
sqlalchemy-bot commentedon Oct 13, 2013
Changes by Michael Bayer (@zzzeek):