summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-01-19 02:19:38 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-01-19 02:19:38 +0000
commit37a61a1b497cb44d0098d188255238ddf4e8e38c (patch)
tree8c261eb58e9b9a6255046bfb05c782d1253fd997
parent4309719ce017876b55929b021cdf2e536003f400 (diff)
downloadsqlalchemy-37a61a1b497cb44d0098d188255238ddf4e8e38c.tar.gz
- 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.
-rw-r--r--CHANGES3
-rw-r--r--lib/sqlalchemy/sql.py8
-rw-r--r--test/sql/select.py5
3 files changed, 14 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index d8cff55de..c85fef967 100644
--- 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]
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py
index 323173cc5..dbd119fd1 100644
--- a/lib/sqlalchemy/sql.py
+++ b/lib/sqlalchemy/sql.py
@@ -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:
diff --git a/test/sql/select.py b/test/sql/select.py
index f11736652..bdc79c400 100644
--- a/test/sql/select.py
+++ b/test/sql/select.py
@@ -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(