From f035b6e0a41238d092ea2ddd10fdd5de298ff789 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 23 Oct 2013 17:41:55 -0400 Subject: An overhaul of expression handling for special symbols particularly with conjunctions, e.g. ``None`` :func:`.expression.null` :func:`.expression.true` :func:`.expression.false`, including consistency in rendering NULL in conjunctions, "short-circuiting" of :func:`.and_` and :func:`.or_` expressions which contain boolean constants, and rendering of boolean constants and expressions as compared to "1" or "0" for backends that don't feature ``true``/``false`` constants. [ticket:2804] --- test/orm/inheritance/test_relationship.py | 1 - 1 file changed, 1 deletion(-) (limited to 'test/orm/inheritance/test_relationship.py') diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py index ecb4bf407..a436ca5fc 100644 --- a/test/orm/inheritance/test_relationship.py +++ b/test/orm/inheritance/test_relationship.py @@ -415,7 +415,6 @@ class M2MFilterTest(fixtures.MappedTest): sess = create_session() e1 = sess.query(Person).filter(Engineer.name == 'e1').one() - # this works eq_(sess.query(Organization) .filter(~Organization.engineers .of_type(Engineer) -- cgit v1.2.1 From ca8fca63916897f1bbc2fa4f1ee440c6b5d9a88a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 2 Jan 2014 18:26:32 -0500 Subject: - Fixed regression where we apparently still create an implicit alias when saying query(B).join(B.cs), where "C" is a joined inh class; however, this implicit alias was created only considering the immediate left side, and not a longer chain of joins along different joined-inh subclasses of the same base. As long as we're still implicitly aliasing in this case, the behavior is dialed back a bit so that it will alias the right side in a wider variety of cases. [ticket:2903] --- test/orm/inheritance/test_relationship.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/orm/inheritance/test_relationship.py') diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py index a436ca5fc..5e047cfdb 100644 --- a/test/orm/inheritance/test_relationship.py +++ b/test/orm/inheritance/test_relationship.py @@ -154,6 +154,7 @@ class SelfReferentialJ2JTest(fixtures.MappedTest): managers.c.person_id == engineers.c.reports_to_id, backref='engineers')}) + def test_has(self): m1 = Manager(name='dogbert') e1 = Engineer(name='dilbert', primary_language='java', reports_to=m1) -- cgit v1.2.1 From 578df5b86b35db97c56e38161ab9dc917269a3b0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 13 Jan 2014 02:38:41 -0500 Subject: - dont run deletes here --- test/orm/inheritance/test_relationship.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/orm/inheritance/test_relationship.py') diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py index 5e047cfdb..bb504c5a3 100644 --- a/test/orm/inheritance/test_relationship.py +++ b/test/orm/inheritance/test_relationship.py @@ -1357,6 +1357,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest): class MultipleAdaptUsesEntityOverTableTest(AssertsCompiledSQL, fixtures.MappedTest): __dialect__ = 'default' run_create_tables = None + run_deletes = None @classmethod def define_tables(cls, metadata): -- cgit v1.2.1 From bd74f81bb5b1158a1bc0a44e9990d4584380c481 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 13 Jan 2014 17:53:37 -0500 Subject: - Fixed a bug involving the new flattened JOIN structures which are used with :func:`.joinedload()` (thereby causing a regression in joined eager loading) as well as :func:`.aliased` in conjunction with the ``flat=True`` flag and joined-table inheritance; basically multiple joins across a "parent JOIN sub" entity using different paths to get to a target class wouldn't form the correct ON conditions. An adjustment / simplification made in the mechanics of figuring out the "left side" of the join in the case of an aliased, joined-inh class repairs the issue. [ticket:2908] --- test/orm/inheritance/test_relationship.py | 134 ++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) (limited to 'test/orm/inheritance/test_relationship.py') diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py index bb504c5a3..db2cd1ec6 100644 --- a/test/orm/inheritance/test_relationship.py +++ b/test/orm/inheritance/test_relationship.py @@ -1354,6 +1354,140 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest): "JOIN ep2 ON anon_1.base2_id = ep2.base2_id" ) +class JoinAcrossJoinedInhMultiPath(fixtures.DeclarativeMappedTest, + testing.AssertsCompiledSQL): + """test long join paths with a joined-inh in the middle, where we go multiple + times across the same joined-inh to the same target but with other classes + in the middle. E.g. test [ticket:2908] + """ + + + run_setup_mappers = 'once' + __dialect__ = 'default' + + @classmethod + def setup_classes(cls): + Base = cls.DeclarativeBasic + + class Root(Base): + __tablename__ = 'root' + + id = Column(Integer, primary_key=True) + sub1_id = Column(Integer, ForeignKey('sub1.id')) + + intermediate = relationship("Intermediate") + sub1 = relationship("Sub1") + + class Intermediate(Base): + __tablename__ = 'intermediate' + + id = Column(Integer, primary_key=True) + sub1_id = Column(Integer, ForeignKey('sub1.id')) + root_id = Column(Integer, ForeignKey('root.id')) + sub1 = relationship("Sub1") + + class Parent(Base): + __tablename__ = 'parent' + + id = Column(Integer, primary_key=True) + + class Sub1(Parent): + __tablename__ = 'sub1' + id = Column(Integer, ForeignKey('parent.id'), + primary_key=True) + + target = relationship("Target") + + class Target(Base): + __tablename__ = 'target' + id = Column(Integer, primary_key=True) + sub1_id = Column(Integer, ForeignKey('sub1.id')) + + def test_join(self): + Root, Intermediate, Sub1, Target = \ + self.classes.Root, self.classes.Intermediate, \ + self.classes.Sub1, self.classes.Target + s1_alias = aliased(Sub1) + s2_alias = aliased(Sub1) + t1_alias = aliased(Target) + t2_alias = aliased(Target) + + sess = Session() + q = sess.query(Root).\ + join(s1_alias, Root.sub1).join(t1_alias, s1_alias.target).\ + join(Root.intermediate).join(s2_alias, Intermediate.sub1).\ + join(t2_alias, s2_alias.target) + self.assert_compile(q, + "SELECT root.id AS root_id, root.sub1_id AS root_sub1_id " + "FROM root " + "JOIN (SELECT parent.id AS parent_id, sub1.id AS sub1_id " + "FROM parent JOIN sub1 ON parent.id = sub1.id) AS anon_1 " + "ON anon_1.sub1_id = root.sub1_id " + "JOIN target AS target_1 ON anon_1.sub1_id = target_1.sub1_id " + "JOIN intermediate ON root.id = intermediate.root_id " + "JOIN (SELECT parent.id AS parent_id, sub1.id AS sub1_id " + "FROM parent JOIN sub1 ON parent.id = sub1.id) AS anon_2 " + "ON anon_2.sub1_id = intermediate.sub1_id " + "JOIN target AS target_2 ON anon_2.sub1_id = target_2.sub1_id") + + def test_join_flat(self): + Root, Intermediate, Sub1, Target = \ + self.classes.Root, self.classes.Intermediate, \ + self.classes.Sub1, self.classes.Target + s1_alias = aliased(Sub1, flat=True) + s2_alias = aliased(Sub1, flat=True) + t1_alias = aliased(Target) + t2_alias = aliased(Target) + + sess = Session() + q = sess.query(Root).\ + join(s1_alias, Root.sub1).join(t1_alias, s1_alias.target).\ + join(Root.intermediate).join(s2_alias, Intermediate.sub1).\ + join(t2_alias, s2_alias.target) + self.assert_compile(q, + "SELECT root.id AS root_id, root.sub1_id AS root_sub1_id " + "FROM root " + "JOIN (parent AS parent_1 JOIN sub1 AS sub1_1 ON parent_1.id = sub1_1.id) " + "ON sub1_1.id = root.sub1_id " + "JOIN target AS target_1 ON sub1_1.id = target_1.sub1_id " + "JOIN intermediate ON root.id = intermediate.root_id " + "JOIN (parent AS parent_2 JOIN sub1 AS sub1_2 ON parent_2.id = sub1_2.id) " + "ON sub1_2.id = intermediate.sub1_id " + "JOIN target AS target_2 ON sub1_2.id = target_2.sub1_id" + ) + + def test_joinedload(self): + Root, Intermediate, Sub1, Target = \ + self.classes.Root, self.classes.Intermediate, \ + self.classes.Sub1, self.classes.Target + + sess = Session() + q = sess.query(Root).\ + options( + joinedload(Root.sub1).joinedload(Sub1.target), + joinedload(Root.intermediate).joinedload(Intermediate.sub1).\ + joinedload(Sub1.target), + ) + self.assert_compile(q, + "SELECT root.id AS root_id, root.sub1_id AS root_sub1_id, " + "target_1.id AS target_1_id, target_1.sub1_id AS target_1_sub1_id, " + "sub1_1.id AS sub1_1_id, parent_1.id AS parent_1_id, " + "intermediate_1.id AS intermediate_1_id, " + "intermediate_1.sub1_id AS intermediate_1_sub1_id, " + "intermediate_1.root_id AS intermediate_1_root_id, " + "target_2.id AS target_2_id, target_2.sub1_id AS target_2_sub1_id, " + "sub1_2.id AS sub1_2_id, parent_2.id AS parent_2_id " + "FROM root " + "LEFT OUTER JOIN intermediate AS intermediate_1 " + "ON root.id = intermediate_1.root_id " + "LEFT OUTER JOIN (parent AS parent_1 JOIN sub1 AS sub1_1 " + "ON parent_1.id = sub1_1.id) ON sub1_1.id = intermediate_1.sub1_id " + "LEFT OUTER JOIN target AS target_1 ON sub1_1.id = target_1.sub1_id " + "LEFT OUTER JOIN (parent AS parent_2 JOIN sub1 AS sub1_2 " + "ON parent_2.id = sub1_2.id) ON sub1_2.id = root.sub1_id " + "LEFT OUTER JOIN target AS target_2 ON sub1_2.id = target_2.sub1_id") + + class MultipleAdaptUsesEntityOverTableTest(AssertsCompiledSQL, fixtures.MappedTest): __dialect__ = 'default' run_create_tables = None -- cgit v1.2.1