Skip to content

Commit

Permalink
Merge branch 'master' of github.com:django-nonrel/mongodb-engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashaag committed Feb 20, 2012
2 parents 18b4788 + fae0467 commit 2d24149
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions django_mongodb_engine/compiler.py
Expand Up @@ -239,9 +239,12 @@ def add_filters(self, filters, query=None):
else: else:
existing.update(lookup) existing.update(lookup)
else: else:
# {'$gt': o1} + {'$lt': o2} --> {'$gt': o1, '$lt': o2} if '$in' in lookup and '$in' in existing:
assert all(key not in existing for key in lookup.keys()), [lookup, existing] existing['$in'] = list(set(lookup['$in'] + existing['$in']))
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)
else: else:
key = '$nin' if self._negated else '$all' key = '$nin' if self._negated else '$all'
existing.setdefault(key, []).append(lookup) existing.setdefault(key, []).append(lookup)
Expand Down
7 changes: 7 additions & 0 deletions tests/query/tests.py
Expand Up @@ -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): def test_negated_Q(self):
blogs = [Blog.objects.create(title=title) for title in blogs = [Blog.objects.create(title=title) for title in
('blog', 'other blog', 'another blog')] ('blog', 'other blog', 'another blog')]
Expand Down

0 comments on commit 2d24149

Please sign in to comment.