diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-27 16:43:01 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-27 16:43:01 -0400 |
commit | fc348366f76bdb3072c69ad8e03f305de38d486c (patch) | |
tree | 1f05d7557819fa35006ca51c1a5a1ec47d861542 /test | |
parent | 3e52710a79857bf9249d71eaf9af0f6ed5edc76a (diff) | |
download | sqlalchemy-fc348366f76bdb3072c69ad8e03f305de38d486c.tar.gz |
- fix a regression caused by #2587, where query.join() would apply an
adapter to an aliased-mapped, non-polymorphic selectable that prevented us from referring
directly to that selectable.
Diffstat (limited to 'test')
-rw-r--r-- | test/orm/test_joins.py | 87 | ||||
-rw-r--r-- | test/orm/test_relationships.py | 2 |
2 files changed, 89 insertions, 0 deletions
diff --git a/test/orm/test_joins.py b/test/orm/test_joins.py index cb9412e1d..21b82f408 100644 --- a/test/orm/test_joins.py +++ b/test/orm/test_joins.py @@ -1732,6 +1732,93 @@ class CreateJoinsTest(fixtures.ORMTest, AssertsCompiledSQL): ")))" ) + +class JoinToNonPolyAliasesTest(fixtures.MappedTest, AssertsCompiledSQL): + """test joins to an aliased selectable and that we can refer to that + aliased selectable in filter criteria. + + Basically testing that the aliasing Query applies to with_polymorphic + targets doesn't leak into non-polymorphic mappers. + + + """ + __dialect__ = 'default' + run_create_tables = None + run_deletes = None + + @classmethod + def define_tables(cls, metadata): + Table("parent", metadata, + Column('id', Integer, primary_key=True), + Column('data', String(50)), + ) + Table("child", metadata, + Column('id', Integer, primary_key=True), + Column('parent_id', Integer, ForeignKey('parent.id')), + Column('data', String(50)) + ) + + @classmethod + def setup_mappers(cls): + parent, child = cls.tables.parent, cls.tables.child + class Parent(cls.Comparable): + pass + + class Child(cls.Comparable): + pass + + mp = mapper(Parent, parent) + mapper(Child, child) + + derived = select([child]).alias() + npc = mapper(Child, derived, non_primary=True) + cls.npc = npc + cls.derived = derived + mp.add_property("npc", relationship(npc)) + + def test_join_parent_child(self): + Parent = self.classes.Parent + npc = self.npc + sess = Session() + self.assert_compile( + sess.query(Parent).join(Parent.npc).filter(self.derived.c.data == 'x'), + "SELECT parent.id AS parent_id, parent.data AS parent_data " + "FROM parent JOIN (SELECT child.id AS id, child.parent_id AS parent_id, " + "child.data AS data " + "FROM child) AS anon_1 ON parent.id = anon_1.parent_id " + "WHERE anon_1.data = :data_1" + ) + + def test_join_parent_child_select_from(self): + Parent = self.classes.Parent + npc = self.npc + sess = Session() + self.assert_compile( + sess.query(npc).select_from(Parent).join(Parent.npc).\ + filter(self.derived.c.data == 'x'), + "SELECT anon_1.id AS anon_1_id, anon_1.parent_id " + "AS anon_1_parent_id, anon_1.data AS anon_1_data " + "FROM parent JOIN (SELECT child.id AS id, child.parent_id AS " + "parent_id, child.data AS data FROM child) AS anon_1 ON " + "parent.id = anon_1.parent_id WHERE anon_1.data = :data_1" + ) + + def test_join_select_parent_child(self): + Parent = self.classes.Parent + npc = self.npc + sess = Session() + self.assert_compile( + sess.query(Parent, npc).join(Parent.npc).filter( + self.derived.c.data == 'x'), + "SELECT parent.id AS parent_id, parent.data AS parent_data, " + "anon_1.id AS anon_1_id, anon_1.parent_id AS anon_1_parent_id, " + "anon_1.data AS anon_1_data FROM parent JOIN " + "(SELECT child.id AS id, child.parent_id AS parent_id, " + "child.data AS data FROM child) AS anon_1 ON parent.id = " + "anon_1.parent_id WHERE anon_1.data = :data_1" + ) + + class SelfReferentialTest(fixtures.MappedTest, AssertsCompiledSQL): run_setup_mappers = 'once' run_inserts = 'once' diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py index 124202dcc..8dc9c3c52 100644 --- a/test/orm/test_relationships.py +++ b/test/orm/test_relationships.py @@ -467,6 +467,8 @@ class CompositeSelfRefFKTest(fixtures.MappedTest): ['emp6', 'emp7'] ) + + class CompositeJoinPartialFK(fixtures.MappedTest, AssertsCompiledSQL): __dialect__ = 'default' @classmethod |