Commits

Mike Bayer committed 893e30b

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.

Comments (0)

Files changed (1)

lib/sqlalchemy/orm/query.py

                         "are the same entity" % 
                         (left, right))
 
-        left_mapper, left_selectable, left_is_aliased = _entity_info(left)
-        right_mapper, right_selectable, right_is_aliased = _entity_info(right)
-
-        if right_mapper:
-            self._join_entities += (right, )
-
-        if right_mapper and prop and \
-                not right_mapper.common_parent(prop.mapper):
-            raise sa_exc.InvalidRequestError(
-                    "Join target %s does not correspond to "
-                    "the right side of join condition %s" % (right, onclause)
-            )
-
-        if not right_mapper and prop:
-            right_mapper = prop.mapper
-
-        need_adapter = False
-
-        if right_mapper and right is right_selectable:
-            if not right_selectable.is_derived_from(
-                                    right_mapper.mapped_table):
-                raise sa_exc.InvalidRequestError(
-                    "Selectable '%s' is not derived from '%s'" %
-                    (right_selectable.description,
-                    right_mapper.mapped_table.description))
-
-            if not isinstance(right_selectable, expression.Alias):
-                right_selectable = right_selectable.alias()
-
-            right = aliased(right_mapper, right_selectable)
-            need_adapter = True
-
-        aliased_entity = right_mapper and \
-                            not right_is_aliased and \
-                            (
-                                right_mapper.with_polymorphic or
-                                isinstance(
-                                    right_mapper.mapped_table,
-                                    expression.Join)
-                            )
-
-        if not need_adapter and (create_aliases or aliased_entity):
-            right = aliased(right)
-            need_adapter = True
+        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
                 '_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:
+            self._join_entities += (right, )
+
+        if right_mapper and prop and \
+                not right_mapper.common_parent(prop.mapper):
+            raise sa_exc.InvalidRequestError(
+                    "Join target %s does not correspond to "
+                    "the right side of join condition %s" % (right, onclause)
+            )
+
+        if not right_mapper and prop:
+            right_mapper = prop.mapper
+
+        need_adapter = False
+
+        if right_mapper and right is right_selectable:
+            if not right_selectable.is_derived_from(
+                                    right_mapper.mapped_table):
+                raise sa_exc.InvalidRequestError(
+                    "Selectable '%s' is not derived from '%s'" %
+                    (right_selectable.description,
+                    right_mapper.mapped_table.description))
+
+            if not isinstance(right_selectable, expression.Alias):
+                right_selectable = right_selectable.alias()
+
+            right = aliased(right_mapper, right_selectable)
+            need_adapter = True
+
+        aliased_entity = right_mapper and \
+                            not right_is_aliased and \
+                            (
+                                right_mapper.with_polymorphic or
+                                isinstance(
+                                    right_mapper.mapped_table,
+                                    expression.Join)
+                            )
+
+        if not need_adapter and (create_aliases or aliased_entity):
+            right = aliased(right)
+            need_adapter = True
+
         # if an alias() of the right side was generated here,
         # apply an adapter to all subsequent filter() calls
         # until reset_joinpoint() is called.
                         )
                     )
 
+        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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.