]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
break up _join_left_to_right to call upon _prepare_right_side and _join_to_left.
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 17 Feb 2012 00:29:00 +0000 (19:29 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 17 Feb 2012 00:29:00 +0000 (19:29 -0500)
this separates the handling of each side totally making it easier to see
what's going on.

lib/sqlalchemy/orm/query.py

index 6321715f4de42488991b6e5a5192d1889d52f91a..e012cd9b05de197a0030162596035856c069a624 100644 (file)
@@ -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