diff options
Diffstat (limited to 'lib/sqlalchemy/orm/strategies.py')
| -rw-r--r-- | lib/sqlalchemy/orm/strategies.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index 944c114a6..a014b2f41 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -1965,6 +1965,9 @@ class JoinedLoader(AbstractRelationshipLoader): ) if user_defined_adapter is not False: + + # setup an adapter but dont create any JOIN, assume it's already + # in the query ( clauses, adapter, @@ -1976,6 +1979,11 @@ class JoinedLoader(AbstractRelationshipLoader): adapter, user_defined_adapter, ) + + # don't do "wrap" for multi-row, we want to wrap + # limited/distinct SELECT, + # because we want to put the JOIN on the outside. + else: # if not via query option, check for # a cycle @@ -1986,6 +1994,7 @@ class JoinedLoader(AbstractRelationshipLoader): elif path.contains_mapper(self.mapper): return + # add the JOIN and create an adapter ( clauses, adapter, @@ -2002,6 +2011,10 @@ class JoinedLoader(AbstractRelationshipLoader): chained_from_outerjoin, ) + # for multi-row, we want to wrap limited/distinct SELECT, + # because we want to put the JOIN on the outside. + compile_state.eager_adding_joins = True + with_poly_entity = path.get( compile_state.attributes, "path_with_polymorphic", None ) |
