From 743ceb045e8be8b606198f4d5c02a72abebb2fbb Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 22 Jan 2014 20:16:47 -0500 Subject: - Support is improved for supplying a :func:`.join` construct as the target of :paramref:`.relationship.secondary` for the purposes of creating very complex :func:`.relationship` join conditions. The change includes adjustments to query joining, joined eager loading to not render a SELECT subquery, changes to lazy loading such that the "secondary" target is properly included in the SELECT, and changes to declarative to better support specification of a join() object with classes as targets. --- test/ext/declarative/test_basic.py | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/ext') diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index 1f14d8164..496aad369 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -409,6 +409,46 @@ class DeclarativeTest(DeclarativeTestBase): "user_1.firstname || :firstname_1 || user_1.lastname" ) + def test_string_dependency_resolution_asselectable(self): + class A(Base): + __tablename__ = 'a' + + id = Column(Integer, primary_key=True) + b_id = Column(ForeignKey('b.id')) + + d = relationship("D", + secondary="join(B, D, B.d_id == D.id)." + "join(C, C.d_id == D.id)", + primaryjoin="and_(A.b_id == B.id, A.id == C.a_id)", + secondaryjoin="D.id == B.d_id", + ) + + class B(Base): + __tablename__ = 'b' + + id = Column(Integer, primary_key=True) + d_id = Column(ForeignKey('d.id')) + + class C(Base): + __tablename__ = 'c' + + id = Column(Integer, primary_key=True) + a_id = Column(ForeignKey('a.id')) + d_id = Column(ForeignKey('d.id')) + + class D(Base): + __tablename__ = 'd' + + id = Column(Integer, primary_key=True) + s = Session() + self.assert_compile( + s.query(A).join(A.d), + "SELECT a.id AS a_id, a.b_id AS a_b_id FROM a JOIN " + "(b AS b_1 JOIN d AS d_1 ON b_1.d_id = d_1.id " + "JOIN c AS c_1 ON c_1.d_id = d_1.id) ON a.b_id = b_1.id " + "AND a.id = c_1.a_id JOIN d ON d.id = b_1.d_id", + ) + def test_string_dependency_resolution_no_table(self): class User(Base, fixtures.ComparableEntity): -- cgit v1.2.1