From aaaac9be475c091f0a1dcb46b76168e6920aa863 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 18 Nov 2007 22:35:19 +0000 Subject: [PATCH] - added tests for [ticket:768] --- CHANGES | 5 ++++- test/orm/query.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 6a6963ab85..d8ed8746f3 100644 --- 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] diff --git a/test/orm/query.py b/test/orm/query.py index d60f72c639..562b1eee22 100644 --- a/test/orm/query.py +++ b/test/orm/query.py @@ -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): -- 2.47.2