Permalink
Browse files

Merge pull request #90 from emperorcezar/master

Fixing issue #85
  • Loading branch information...
2 parents 4814421 + 128038a commit fae046738c1c58f7532d6a6c3d35c629e824f300 @jonashaag jonashaag committed Feb 18, 2012
Showing with 13 additions and 3 deletions.
  1. +6 −3 django_mongodb_engine/compiler.py
  2. +7 −0 tests/query/tests.py
@@ -239,9 +239,12 @@ def add_filters(self, filters, query=None):
else:
existing.update(lookup)
else:
- # {'$gt': o1} + {'$lt': o2} --> {'$gt': o1, '$lt': o2}
- assert all(key not in existing for key in lookup.keys()), [lookup, existing]
- existing.update(lookup)
+ if '$in' in lookup and '$in' in existing:
+ existing['$in'] = list(set(lookup['$in'] + existing['$in']))
+ else:
+ # {'$gt': o1} + {'$lt': o2} --> {'$gt': o1, '$lt': o2}
+ assert all(key not in existing for key in lookup.keys()), [lookup, existing]
+ existing.update(lookup)
else:
key = '$nin' if self._negated else '$all'
existing.setdefault(key, []).append(lookup)
View
@@ -234,6 +234,13 @@ def test_multiple_filter_on_same_name(self):
[]
)
+ # Tests chaining on primary keys
+ blog_id = Blog.objects.get().id
+ self.assertEqual(
+ Blog.objects.filter(pk = blog_id).filter(pk = blog_id).get(),
+ Blog.objects.get()
+ )
+
def test_negated_Q(self):
blogs = [Blog.objects.create(title=title) for title in
('blog', 'other blog', 'another blog')]

0 comments on commit fae0467

Please sign in to comment.