]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- made some fixes to the "from_joinpoint" argument to
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 21 Mar 2008 17:21:41 +0000 (17:21 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 21 Mar 2008 17:21:41 +0000 (17:21 +0000)
query.join() so that if the previous join was aliased
and this one isn't, the join still happens successfully.

CHANGES
lib/sqlalchemy/orm/query.py
test/orm/query.py

diff --git a/CHANGES b/CHANGES
index 002f0fa5d30a4ec7e7f5d57d11edbbc97bd59631..b5c8972e89f2e3095ed7e3e43e544b9a14bace98 100644 (file)
--- 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
index 3812639259c0e1600b785fffce8e9c492ed6be46..ad8ec33f8ead1fd401a481c22b29a4699705c727 100644 (file)
@@ -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
 
index 3430a395f7638c42f6e2963d0fedb138829d1607..e2031863b06d276428ed96624f0edfe84a8c6f96 100644 (file)
@@ -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()