]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- another fix to subquery correlation so that a subquery which has only one FROM
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Jan 2007 02:19:38 +0000 (02:19 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Jan 2007 02:19:38 +0000 (02:19 +0000)
element will *not* correlate that single element, since at least one FROM element is
required in a query.

CHANGES
lib/sqlalchemy/sql.py
test/sql/select.py

diff --git a/CHANGES b/CHANGES
index d8cff55dec3c8967acf3b3eae8986f592b365766..c85fef9676b5df11fd578523df690ba274e59644 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,9 @@
   is constructed with individual calls to append_column(); this fixes an ORM
   bug whereby nested select statements were not getting correlated with the 
   main select generated by the Query object.
+  - another fix to subquery correlation so that a subquery which has only one FROM
+  element will *not* correlate that single element, since at least one FROM element is 
+  required in a query.
   - default "timezone" setting is now False.  this corresponds to Python's datetime
   behavior as well as Postgres' timestamp/time types (which is the only timezone-sensitive
   dialect at the moment) [ticket:414]
index 323173cc56150ae5e65b82e000ae6dc306ff4f5c..dbd119fd1ef32946a966ae634e3b3cb6e6ef1fc4 100644 (file)
@@ -1580,7 +1580,13 @@ class Select(_SelectBaseMixin, FromClause):
         else:
             return None
 
-    froms = property(lambda self: self.__froms.difference(self.__hide_froms).difference(self.__correlated), doc="""a collection containing all elements of the FROM clause""")
+    def _calc_froms(self):
+        f = self.__froms.difference(self.__hide_froms)
+        if (len(f) > 1):
+            return f.difference(self.__correlated)
+        else:
+            return f
+    froms = property(_calc_froms, doc="""a collection containing all elements of the FROM clause""")
 
     def accept_visitor(self, visitor):
         for f in self.froms:
index f1173665298fb8eaef7a11d25d1b541048df90b5..bdc79c400b19c344c777165b2adb2b08c4af23fb 100644 (file)
@@ -121,7 +121,10 @@ sq2.sq_myothertable_otherid, sq2.sq_myothertable_othername FROM \
 (SELECT sq.mytable_myid AS sq_mytable_myid, sq.mytable_name AS sq_mytable_name, \
 sq.mytable_description AS sq_mytable_description, sq.myothertable_otherid AS sq_myothertable_otherid, \
 sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") AS sq) AS sq2")
-
+    
+    def testdontovercorrelate(self):
+        self.runtest(select([table1], from_obj=[table1, table1.select()]), """SELECT mytable.myid, mytable.name, mytable.description FROM mytable, (SELECT mytable.myid AS myid, mytable.name AS name, mytable.description AS description FROM mytable)""")
+        
     def testwheresubquery(self):
         # TODO: this tests that you dont get a "SELECT column" without a FROM but its not working yet.
         #self.runtest(