diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-02-05 23:26:37 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-02-05 23:26:37 +0000 |
commit | 55d455d7d0d4d67d9f3d13cf74de471c15ce5d50 (patch) | |
tree | 3e924f84e2b28d78e0e15e8401f42f777006073e | |
parent | 54c5a4764233f515f696e667596364666f558473 (diff) | |
download | sqlalchemy-55d455d7d0d4d67d9f3d13cf74de471c15ce5d50.tar.gz |
- added distinct() method to SelectResults. generally should only make a difference
when using count().
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/selectresults.py | 6 | ||||
-rw-r--r-- | test/orm/eagertest3.py | 4 |
3 files changed, 13 insertions, 2 deletions
@@ -38,7 +38,10 @@ - postgres: - better reflection of sequences for alternate-schema Tables [ticket:442] - sequences on a non-pk column will properly fire off on INSERT - +- ext: + - added distinct() method to SelectResults. generally should only make a difference + when using count(). + 0.3.4 - general: - global "insure"->"ensure" change. in US english "insure" is actually diff --git a/lib/sqlalchemy/ext/selectresults.py b/lib/sqlalchemy/ext/selectresults.py index 3e7fa93c8..5ad961f0a 100644 --- a/lib/sqlalchemy/ext/selectresults.py +++ b/lib/sqlalchemy/ext/selectresults.py @@ -89,6 +89,12 @@ class SelectResults(object): """apply an OFFSET to the query.""" return self[offset:] + def distinct(self): + """applies a DISTINCT to the query""" + new = self.clone() + new._ops['distinct'] = True + return new + def list(self): """return the results represented by this SelectResults as a list. diff --git a/test/orm/eagertest3.py b/test/orm/eagertest3.py index 5b498c0c8..1db029847 100644 --- a/test/orm/eagertest3.py +++ b/test/orm/eagertest3.py @@ -318,7 +318,9 @@ class EagerTest4(testbase.ORMTest): filters = [q.join_to('employees'), Employee.c.name.startswith('J')] - d = SelectResults(q, and_(*filters), ops=dict(distinct=True)) + d = SelectResults(q) + d = d.join_to('employees').filter(Employee.c.name.startswith('J')) + d = d.distinct() d = d.order_by([desc(Department.c.name)]) assert d.count() == 2 assert d[0] is d2 |