summaryrefslogtreecommitdiff
path: root/test/orm/query.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-03-21 16:12:37 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-03-21 16:12:37 +0000
commit0983b610b47d2cbe502837ded365a2d2dbcdc883 (patch)
treea43a8311554a871cefa6f691dc5a3b62f463997b /test/orm/query.py
parent3ecf84f5adb428f814cd18b47ac65d133112cbf0 (diff)
downloadsqlalchemy-0983b610b47d2cbe502837ded365a2d2dbcdc883.tar.gz
- An alias() of a select() will convert to a "scalar subquery"
when used in an unambiguously scalar context, i.e. it's used in a comparison operation. This applies to the ORM when using query.subquery() as well.
Diffstat (limited to 'test/orm/query.py')
-rw-r--r--test/orm/query.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/test/orm/query.py b/test/orm/query.py
index d5ed96d4b..1d13a6c45 100644
--- a/test/orm/query.py
+++ b/test/orm/query.py
@@ -525,7 +525,16 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
l = list(session.query(User).instances(s.execute(emailad = 'jack@bean.com')))
eq_([User(id=7)], l)
-
+ def test_scalar_subquery(self):
+ session = create_session()
+
+ q = session.query(User.id).filter(User.id==7).subquery()
+
+ q = session.query(User).filter(User.id==q)
+
+ eq_(User(id=7), q.one())
+
+
def test_in(self):
session = create_session()
s = session.query(User.id).join(User.addresses).group_by(User.id).having(func.count(Address.id) > 2)
@@ -1742,7 +1751,7 @@ class MixedEntitiesTest(QueryTest):
q2 = q.group_by([User.name.like('%j%')]).order_by(desc(User.name.like('%j%'))).values(User.name.like('%j%'), func.count(User.name.like('%j%')))
self.assertEquals(list(q2), [(True, 1), (False, 3)])
- def test_scalar_subquery(self):
+ def test_correlated_subquery(self):
"""test that a subquery constructed from ORM attributes doesn't leak out
those entities to the outermost query.