Added match ($elemMatch) support for EmbeddedDocuments (#379)
This commit is contained in:
parent
9867e918fa
commit
d6edef98c6
@ -4,6 +4,7 @@ Changelog
|
||||
|
||||
Changes in 0.8.3
|
||||
================
|
||||
- Added match ($elemMatch) support for EmbeddedDocuments (#379)
|
||||
- Fixed weakref being valid after reload (#374)
|
||||
- Fixed queryset.get() respecting no_dereference (#373)
|
||||
- Added full_result kwarg to update (#380)
|
||||
|
@ -95,6 +95,7 @@ def query(_doc_cls=None, _field_operation=False, **query):
|
||||
value = _geo_operator(field, op, value)
|
||||
elif op in CUSTOM_OPERATORS:
|
||||
if op == 'match':
|
||||
value = field.prepare_query_value(op, value)
|
||||
value = {"$elemMatch": value}
|
||||
else:
|
||||
NotImplementedError("Custom method '%s' has not "
|
||||
|
@ -3091,7 +3091,7 @@ class QuerySetTest(unittest.TestCase):
|
||||
class Foo(EmbeddedDocument):
|
||||
shape = StringField()
|
||||
color = StringField()
|
||||
trick = BooleanField()
|
||||
thick = BooleanField()
|
||||
meta = {'allow_inheritance': False}
|
||||
|
||||
class Bar(Document):
|
||||
@ -3100,17 +3100,20 @@ class QuerySetTest(unittest.TestCase):
|
||||
|
||||
Bar.drop_collection()
|
||||
|
||||
b1 = Bar(foo=[Foo(shape= "square", color ="purple", thick = False),
|
||||
Foo(shape= "circle", color ="red", thick = True)])
|
||||
b1 = Bar(foo=[Foo(shape="square", color="purple", thick=False),
|
||||
Foo(shape="circle", color="red", thick=True)])
|
||||
b1.save()
|
||||
|
||||
b2 = Bar(foo=[Foo(shape= "square", color ="red", thick = True),
|
||||
Foo(shape= "circle", color ="purple", thick = False)])
|
||||
b2 = Bar(foo=[Foo(shape="square", color="red", thick=True),
|
||||
Foo(shape="circle", color="purple", thick=False)])
|
||||
b2.save()
|
||||
|
||||
ak = list(Bar.objects(foo__match={'shape': "square", "color": "purple"}))
|
||||
self.assertEqual([b1], ak)
|
||||
|
||||
ak = list(Bar.objects(foo__match=Foo(shape="square", color="purple")))
|
||||
self.assertEqual([b1], ak)
|
||||
|
||||
def test_upsert_includes_cls(self):
|
||||
"""Upserts should include _cls information for inheritable classes
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user