]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug in Query whereby calling q.join(prop).from_self(...).
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Mar 2010 17:16:21 +0000 (13:16 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Mar 2010 17:16:21 +0000 (13:16 -0400)
join(prop) would fail to render the second join outside the
subquery, when joining on the same criterion as was on the
inside.

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

diff --git a/CHANGES b/CHANGES
index 5453f6e510b867d3287778554c1bbeb0402bafdb..baa8e03188d480611609c527717a626c085a34f1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,15 @@
 CHANGES
 =======
 
+0.6beta3
+========
+
+- orm
+  - Fixed bug in Query whereby calling q.join(prop).from_self(...).
+    join(prop) would fail to render the second join outside the
+    subquery, when joining on the same criterion as was on the 
+    inside.
+
 0.6beta2
 ========
 
index 8d3d7fbb36a98d5a7709020088330e8c7f24d819..7ae1194c1f7f8036ac10dfd01afbc1a3845d6987 100644 (file)
@@ -627,9 +627,11 @@ class Query(object):
 
     @_generative()
     def _from_selectable(self, fromclause):
-        self._statement = self._criterion = None
-        self._order_by = self._group_by = self._distinct = False
-        self._limit = self._offset = None
+        for attr in ('_statement', '_criterion', '_order_by', '_group_by',
+                '_limit', '_offset', '_joinpath', '_joinpoint', 
+                '_distinct'
+        ):
+            self.__dict__.pop(attr, None)
         self._set_select_from(fromclause)
         old_entities = self._entities
         self._entities = []
index fa5211e3efaa400ba5121b09cc6b274fea72cba6..cd76f53b0cea422fe3e6fa1e05654b5405d83c5d 100644 (file)
@@ -2275,6 +2275,25 @@ class JoinTest(QueryTest, AssertsCompiledSQL):
             [(u'jack',), (u'ed',), (u'ed',), (u'ed',), (u'fred',)]
         )
         
+    def test_from_self_resets_joinpaths(self):
+        """test a join from from_self() doesn't confuse joins inside the subquery
+        with the outside.
+        """
+        sess = create_session()
+        
+        self.assert_compile(
+            sess.query(Item).join(Item.keywords).from_self(Keyword).join(Item.keywords),
+            "SELECT keywords.id AS keywords_id, keywords.name AS keywords_name FROM "
+            "(SELECT items.id AS items_id, items.description AS items_description "
+            "FROM items JOIN item_keywords AS item_keywords_1 ON items.id = "
+            "item_keywords_1.item_id JOIN keywords ON keywords.id = item_keywords_1.keyword_id) "
+            "AS anon_1 JOIN item_keywords AS item_keywords_2 ON "
+            "anon_1.items_id = item_keywords_2.item_id "
+            "JOIN keywords ON "
+            "keywords.id = item_keywords_2.keyword_id",
+            use_default_dialect=True
+        )
+        
         
 class MultiplePathTest(_base.MappedTest, AssertsCompiledSQL):
     @classmethod