From 35cba3c84ab9c36663e57049e56e59cace5aa2f7 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 16 Feb 2012 19:29:00 -0500 Subject: [PATCH] break up _join_left_to_right to call upon _prepare_right_side and _join_to_left. this separates the handling of each side totally making it easier to see what's going on. --- lib/sqlalchemy/orm/query.py | 41 +++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 6321715f4d..e012cd9b05 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1692,7 +1692,29 @@ class Query(object): "are the same entity" % (left, right)) - left_mapper, left_selectable, left_is_aliased = _entity_info(left) + right, right_is_aliased, onclause = self._prepare_right_side( + right, onclause, + outerjoin, create_aliases, + prop) + + # if joining on a MapperProperty path, + # track the path to prevent redundant joins + if not create_aliases and prop: + self._update_joinpoint({ + '_joinpoint_entity':right, + 'prev':((left, right, prop.key), self._joinpoint) + }) + else: + self._joinpoint = { + '_joinpoint_entity':right + } + + self._join_to_left(left, right, + right_is_aliased, + onclause, outerjoin) + + def _prepare_right_side(self, right, onclause, outerjoin, + create_aliases, prop): right_mapper, right_selectable, right_is_aliased = _entity_info(right) if right_mapper: @@ -1737,18 +1759,6 @@ class Query(object): right = aliased(right) need_adapter = True - # if joining on a MapperProperty path, - # track the path to prevent redundant joins - if not create_aliases and prop: - self._update_joinpoint({ - '_joinpoint_entity':right, - 'prev':((left, right, prop.key), self._joinpoint) - }) - else: - self._joinpoint = { - '_joinpoint_entity':right - } - # if an alias() of the right side was generated here, # apply an adapter to all subsequent filter() calls # until reset_joinpoint() is called. @@ -1776,6 +1786,11 @@ class Query(object): ) ) + return right, right_is_aliased, onclause + + def _join_to_left(self, left, right, right_is_aliased, onclause, outerjoin): + left_mapper, left_selectable, left_is_aliased = _entity_info(left) + # this is an overly broad assumption here, but there's a # very wide variety of situations where we rely upon orm.join's # adaption to glue clauses together, with joined-table inheritance's -- 2.47.2