From 0410eae36b36dc8ea7e747c4b81c7ec9de5f2da4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 3 Dec 2008 17:28:36 +0000 Subject: - Two fixes to help prevent out-of-band columns from being rendered in polymorphic_union inheritance scenarios (which then causes extra tables to be rendered in the FROM clause causing cartesian products): - improvements to "column adaption" for a->b->c inheritance situations to better locate columns that are related to one another via multiple levels of indirection, rather than rendering the non-adapted column. - the "polymorphic discriminator" column is only rendered for the actual mapper being queried against. The column won't be "pulled in" from a subclass or superclass mapper since it's not needed. --- test/sql/generative.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/sql') diff --git a/test/sql/generative.py b/test/sql/generative.py index f6b849e8a..4edf334f6 100644 --- a/test/sql/generative.py +++ b/test/sql/generative.py @@ -458,6 +458,32 @@ class ClauseAdapterTest(TestBase, AssertsCompiledSQL): assert str(e) == "a_1.id = a.xxx_id" + def test_recursive_equivalents(self): + m = MetaData() + a = Table('a', m, Column('x', Integer), Column('y', Integer)) + b = Table('b', m, Column('x', Integer), Column('y', Integer)) + c = Table('c', m, Column('x', Integer), Column('y', Integer)) + + # force a recursion overflow, by linking a.c.x<->c.c.x, and + # asking for a nonexistent col. corresponding_column should prevent + # endless depth. + adapt = sql_util.ClauseAdapter( b, equivalents= {a.c.x: set([ c.c.x]), c.c.x:set([a.c.x])}) + assert adapt._corresponding_column(a.c.x, False) is None + + def test_multilevel_equivalents(self): + m = MetaData() + a = Table('a', m, Column('x', Integer), Column('y', Integer)) + b = Table('b', m, Column('x', Integer), Column('y', Integer)) + c = Table('c', m, Column('x', Integer), Column('y', Integer)) + + alias = select([a]).select_from(a.join(b, a.c.x==b.c.x)).alias() + + # two levels of indirection from c.x->b.x->a.x, requires recursive + # corresponding_column call + adapt = sql_util.ClauseAdapter(alias, equivalents= {b.c.x: set([ a.c.x]), c.c.x:set([b.c.x])}) + assert adapt._corresponding_column(a.c.x, False) is alias.c.x + assert adapt._corresponding_column(c.c.x, False) is alias.c.x + def test_join_to_alias(self): metadata = MetaData() a = Table('a', metadata, -- cgit v1.2.1