From: Mike Bayer Date: Fri, 21 Mar 2008 17:21:41 +0000 (+0000) Subject: - made some fixes to the "from_joinpoint" argument to X-Git-Tag: rel_0_4_5~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bc2784a4d2ce6f880c9d36daad4205127f6336b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - made some fixes to the "from_joinpoint" argument to query.join() so that if the previous join was aliased and this one isn't, the join still happens successfully. --- diff --git a/CHANGES b/CHANGES index 002f0fa5d3..b5c8972e89 100644 --- a/CHANGES +++ b/CHANGES @@ -24,6 +24,10 @@ CHANGES any two mappers with a common parent (this affects whether or not aliased=True is required when joining with Query). + + - made some fixes to the "from_joinpoint" argument to + query.join() so that if the previous join was aliased + and this one isn't, the join still happens successfully. - assorted "cascade deletes" fixes: - Fixed "cascade delete" operation of dynamic diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 3812639259..ad8ec33f8e 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -490,6 +490,8 @@ class Query(object): adapt_against = self.table elif start.select_table is not start.mapped_table: # in the middle of a join, look for a polymorphic mapper adapt_against = start.select_table + elif self._aliases: # joining against aliases + adapt_against = self._aliases.alias else: adapt_against = None diff --git a/test/orm/query.py b/test/orm/query.py index 3430a395f7..e2031863b0 100644 --- a/test/orm/query.py +++ b/test/orm/query.py @@ -575,7 +575,24 @@ class JoinTest(QueryTest): def test_overlapping_paths_outerjoin(self): result = create_session().query(User).outerjoin(['orders', 'items']).filter_by(id=3).outerjoin(['orders','address']).filter_by(id=1).all() assert [User(id=7, name='jack')] == result + + def test_from_joinpoint(self): + sess = create_session() + + for oalias,ialias in [(True, True), (False, False), (True, False), (False, True)]: + self.assertEquals( + sess.query(User).join('orders', aliased=oalias).join('items', from_joinpoint=True, aliased=ialias).filter(Item.description == 'item 4').all(), + [User(name='jack')] + ) + # use middle criterion + self.assertEquals( + sess.query(User).join('orders', aliased=oalias).filter(Order.user_id==9).join('items', from_joinpoint=True, aliased=ialias).filter(Item.description=='item 4').all(), + [] + ) + + + def test_generative_join(self): # test that alised_ids is copied sess = create_session()