]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fix to using distinct() or distinct=True in combination with
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Apr 2007 20:30:55 +0000 (20:30 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Apr 2007 20:30:55 +0000 (20:30 +0000)
join() and similar

CHANGES
lib/sqlalchemy/orm/query.py
test/orm/mapper.py

diff --git a/CHANGES b/CHANGES
index 934733d0b1d4e13547690216eb4066f0ad394b10..ea7e68d6c660a1669526e27bdb76c2917e517349 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -89,6 +89,8 @@
     - added generative versions of aggregates, i.e. sum(), avg(), etc.
       to query. used via query.apply_max(), apply_sum(), etc. 
       #552
+    - fix to using distinct() or distinct=True in combination with 
+      join() and similar
     - corresponding to label/bindparam name generataion, eager loaders 
       generate deterministic names for the aliases they create using 
       md5 hashes.
index edbd53fdcaeab533057ac26723c903994e29db68..355ba68f799f1e8a238c65d4c5475128f01999af 100644 (file)
@@ -344,7 +344,7 @@ class Query(object):
         if self.table not in alltables:
             from_obj.append(self.table)
         if self._nestable(**kwargs):
-            s = sql.select([self.table], whereclause, **kwargs).alias('getcount').count()
+            s = sql.select([self.table], whereclause, from_obj=from_obj, **kwargs).alias('getcount').count()
         else:
             primary_key = self.primary_key_columns
             s = sql.select([sql.func.count(list(primary_key)[0])], whereclause, from_obj=from_obj, **kwargs)
index 08faf721f95b126197b060e4c49452acfab0783c..8a0f28c478abd3d9e8d5b94e1b58ec93a3341441 100644 (file)
@@ -459,7 +459,7 @@ class MapperTest(MapperSuperTest):
         
     @testbase.unsupported('firebird') 
     def testcount(self):
-        """test the count function on Query
+        """test the count function on Query.
         
         (why doesnt this work on firebird?)"""
         mapper(User, users)
@@ -467,7 +467,13 @@ class MapperTest(MapperSuperTest):
         self.assert_(q.count()==3)
         self.assert_(q.count(users.c.user_id.in_(8,9))==2)
         self.assert_(q.count_by(user_name='fred')==1)
-            
+
+    def testmanytomany_count(self):
+        mapper(Item, orderitems, properties = dict(
+                keywords = relation(mapper(Keyword, keywords), itemkeywords, lazy = True),
+            ))
+        q = create_session().query(Item)
+        assert q.join('keywords').distinct().count(Keyword.c.name=="red") == 2
 
     def testoverride(self):
         # assert that overriding a column raises an error
@@ -1098,7 +1104,9 @@ class LazyTest(MapperSuperTest):
             {'item_id' : 1, 'keywords' : (Keyword, [{'keyword_id' : 2}, {'keyword_id' : 4}, {'keyword_id' : 6}])},
             {'item_id' : 2, 'keywords' : (Keyword, [{'keyword_id' : 2}, {'keyword_id' : 5}, {'keyword_id' : 7}])},
         )
+    
 
+        
 class EagerTest(MapperSuperTest):
     def testbasic(self):
         """tests a basic one-to-many eager load"""