]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- identify another condition, indirectly via #2491, where
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 24 May 2012 14:58:43 +0000 (10:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 24 May 2012 14:58:43 +0000 (10:58 -0400)
remote/local detection was regressing vs. 0.7.   use a more
liberal check for "tables overlap".

lib/sqlalchemy/orm/relationships.py
test/orm/test_rel_fn.py

index 9b828ee047490a3cfb0ca3a312b8b7db9461b5f6..55c5071df11bb672e44c2eeb018cadf46707084b 100644 (file)
@@ -16,7 +16,7 @@ and `secondaryjoin` aspects of :func:`.relationship`.
 from sqlalchemy import sql, util, log, exc as sa_exc, schema
 from sqlalchemy.sql.util import ClauseAdapter, criterion_as_pairs, \
     join_condition, _shallow_annotate, visit_binary_product,\
-    _deep_deannotate
+    _deep_deannotate, find_tables
 from sqlalchemy.sql import operators, expression, visitors
 from sqlalchemy.orm.interfaces import MANYTOMANY, MANYTOONE, ONETOMANY
 
@@ -418,10 +418,11 @@ class JoinCondition(object):
     def _tables_overlap(self):
         """Return True if parent/child tables have some overlap."""
 
-        return self.parent_selectable.is_derived_from(
-                        self.child_local_selectable) or \
-            self.child_selectable.is_derived_from(
-                        self.parent_local_selectable)
+        return  bool(
+            set(find_tables(self.parent_selectable)).intersection(
+                find_tables(self.child_selectable)
+            )
+        )
 
     def _annotate_remote(self):
         """Annotate the primaryjoin and secondaryjoin
index c00a903fa91316622772e05c0f949c1086bb6eaf..3f43762be6dfcb5c9ab08ed5e316272dc6153814 100644 (file)
@@ -288,6 +288,20 @@ class _JoinFixtures(object):
             primaryjoin=self.sub_w_base_rel.c.base_id==self.base.c.id
         )
 
+    def _join_fixture_m2o_joined_sub_to_sub_on_base(self, **kw):
+        # this is a late add - a variant of the test case
+        # in #2491 where we join on the base cols instead.  only 
+        # m2o has a problem at the time of this test.
+        left = self.base.join(self.sub, self.base.c.id==self.sub.c.id)
+        right = self.base.join(self.sub_w_base_rel, self.base.c.id==self.sub_w_base_rel.c.id)
+        return relationships.JoinCondition(
+            left, 
+            right,
+            self.sub,
+            self.sub_w_base_rel,
+            primaryjoin=self.sub_w_base_rel.c.base_id==self.base.c.id,
+        )
+
     def _join_fixture_o2m_joined_sub_to_sub(self, **kw):
         left = self.base.join(self.sub, self.base.c.id==self.sub.c.id)
         right = self.base.join(self.sub_w_sub_rel, self.base.c.id==self.sub_w_sub_rel.c.id)
@@ -473,6 +487,13 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL
             [(self.left.c.id, self.right.c.lid)]
         )
 
+    def test_determinelocal_remote_m2o_joined_sub_to_sub_on_base(self):
+        joincond = self._join_fixture_m2o_joined_sub_to_sub_on_base()
+        eq_(
+            joincond.local_remote_pairs,
+            [(self.base.c.id, self.sub_w_base_rel.c.base_id)]
+        )
+
     def test_determine_local_remote_base_to_joined_sub(self):
         joincond = self._join_fixture_base_to_joined_sub()
         eq_(
@@ -501,17 +522,6 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL
         )
 
     def test_determine_remote_columns_o2m_joined_sub_to_sub(self):
-        def _join_fixture_o2m_joined_sub_to_sub(self, **kw):
-            left = self.base.join(self.sub, self.base.c.id==self.sub.c.id)
-            right = self.base.join(self.sub_w_sub_rel, self.base.c.id==self.sub_w_sub_rel.c.id)
-            return relationships.JoinCondition(
-                left,
-                right,
-                self.sub,
-                self.sub_w_sub_rel,
-                primaryjoin=self.sub.c.id==self.sub_w_sub_rel.c.sub_id
-            )
-
         joincond = self._join_fixture_o2m_joined_sub_to_sub()
         eq_(
             joincond.local_remote_pairs,