]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add further coverage for join_condition to make sure we get this case where
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Mar 2014 20:41:08 +0000 (16:41 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Mar 2014 20:41:08 +0000 (16:41 -0400)
there are multiple, equivalent foreign keys

lib/sqlalchemy/sql/selectable.py
test/sql/test_selectable.py

index ce48d4c4b44eb81b8cd79176dc627d06c9404075..f64a70ec8d3f8b1d65db2135aeed886a49dcc792 100644 (file)
@@ -740,7 +740,7 @@ class Join(FromClause):
             if len(constraints) > 1:
                 dedupe = set(tuple(crit) for crit in constraints.values())
                 if len(dedupe) == 1:
-                    key = constraints.keys()[0]
+                    key = list(constraints)[0]
                     constraints = {key: constraints[key]}
 
             if len(constraints) != 1:
index 5d3d53b8885e36b41c74d6c86117a0f87fd11ad2..a5693acd3b46d13fb93f7d10700c58a5b6dfb677 100644 (file)
@@ -1062,6 +1062,16 @@ class JoinConditionTest(fixtures.TestBase, AssertsCompiledSQL):
                 "FROM t2 JOIN t3 ON t2.id = t3.t2id) ON t2.id = t3_t2id")
 
 
+    def test_join_multiple_equiv_fks(self):
+        m = MetaData()
+        t1 = Table('t1', m,
+                Column('id', Integer, primary_key=True)
+            )
+        t2 = Table('t2', m,
+                Column('t1id', Integer, ForeignKey('t1.id'), ForeignKey('t1.id'))
+                )
+
+        assert sql_util.join_condition(t1, t2).compare(t1.c.id == t2.c.t1id)
 
     def test_join_cond_no_such_unrelated_table(self):
         m = MetaData()