]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added tests for [ticket:768]
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Nov 2007 22:35:19 +0000 (22:35 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Nov 2007 22:35:19 +0000 (22:35 +0000)
CHANGES
test/orm/query.py

diff --git a/CHANGES b/CHANGES
index 6a6963ab85dac1dcb989302ce9200f84195de6c7..d8ed8746f39408fd7999046c723e4c88ddb0ccfa 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -110,7 +110,10 @@ CHANGES
     
   - query doesn't throw an error if you use distinct() and an order_by()
     containing UnaryExpressions (or other) together [ticket:848]
-
+  
+  - order_by() expressions from joined tables are properly added to columns 
+    clause when using distinct() [ticket:786]
+    
   - fixed error where Query.add_column() would not accept a class-bound
     attribute as an argument; Query also raises an error if an invalid
     argument was sent to add_column() (at instances() time) [ticket:858]
index d60f72c639cc2480f2ef1d23f2ac8780639f8914..562b1eee22c6321cbc13ac399e4e7d64173f31de 100644 (file)
@@ -363,6 +363,30 @@ class DistinctTest(QueryTest):
     def test_basic(self):
         assert [User(id=7), User(id=8), User(id=9),User(id=10)] == create_session().query(User).distinct().all()
         assert [User(id=7), User(id=9), User(id=8),User(id=10)] == create_session().query(User).distinct().order_by(desc(User.name)).all()
+
+    def test_joined(self):
+        """test that orderbys from a joined table get placed into the columns clause when DISTINCT is used"""
+        
+        sess = create_session()
+        q = sess.query(User).join('addresses').distinct().order_by(desc(Address.email_address))
+
+        assert [User(id=7), User(id=9), User(id=8)] == q.all()
+
+        sess.clear()
+        
+        # test that it works on embedded eagerload/LIMIT subquery 
+        q = sess.query(User).join('addresses').distinct().options(eagerload('addresses')).order_by(desc(Address.email_address)).limit(2)
+
+        def go():
+            assert [
+                User(id=7, addresses=[
+                    Address(id=1)
+                ]), 
+                User(id=9, addresses=[
+                    Address(id=5)
+                ]), 
+            ] == q.all()
+        self.assert_sql_count(testbase.db, go, 1)
         
     
 class TextTest(QueryTest):