diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-03-28 16:41:08 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-03-28 16:41:08 -0400 |
commit | 9c731b2ebf4909d319bf7ce44c4c5e895723afa6 (patch) | |
tree | 923d3c5351290dc9c2ee185056f29e3f0984ff96 | |
parent | a04fb820289d10b4f340810e23242b4025e7c195 (diff) | |
download | sqlalchemy-9c731b2ebf4909d319bf7ce44c4c5e895723afa6.tar.gz |
- add further coverage for join_condition to make sure we get this case where
there are multiple, equivalent foreign keys
-rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 2 | ||||
-rw-r--r-- | test/sql/test_selectable.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index ce48d4c4b..f64a70ec8 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -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: diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 5d3d53b88..a5693acd3 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -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() |