django-nonrel / djangotoolbox

Django tools for building nonrel backends
BSD 3-Clause "New" or "Revised" License
200 stars 125 forks source link

Allow Distinct Queries #49

Open gurelkaynak opened 10 years ago

gurelkaynak commented 10 years ago

I'm using django-nonrel 1.6-beta with djangotoolbox. Some of my admin pages needed to use DISTINCT but djangotoolbox prevented that in /db/basecompiler.py line 451:

diff --git a/djangotoolbox/db/basecompiler.py b/djangotoolbox/db/basecompiler.py
index 71d9ec8..47fa95b 100644
--- a/djangotoolbox/db/basecompiler.py
+++ b/djangotoolbox/db/basecompiler.py
@@ -451,7 +451,7 @@ class NonrelCompiler(SQLCompiler):
             raise EmptyResultSet()
         if (len([a for a in self.query.alias_map if
                  self.query.alias_refcount[a]]) > 1 or
-            self.query.distinct or self.query.extra or self.query.having):
+            self.query.extra or self.query.having):
             raise DatabaseError("This query is not supported by the database.")

     def get_count(self, check_exists=False):

Can somebody explain why using distinct raises this DatabaseError?

I'll also try to push this to a branch.

Thank you.

gurelkaynak commented 10 years ago

I realized that distinct queries are not supported by django_mongo_engine...

gurelkaynak commented 10 years ago

Actually they seem to be supported like this distinct('foo'). When called without arguments it doesn't work.