Fixed issue with unset operation
This commit is contained in:
parent
cec8b67b08
commit
3a0523dd79
@ -917,8 +917,7 @@ class QuerySet(object):
|
||||
|
||||
# Convert value to proper value
|
||||
field = fields[-1]
|
||||
if op in (None, 'set', 'unset', 'pop', 'push', 'pull',
|
||||
'addToSet'):
|
||||
if op in (None, 'set', 'push', 'pull', 'addToSet'):
|
||||
value = field.prepare_query_value(op, value)
|
||||
elif op in ('pushAll', 'pullAll'):
|
||||
value = [field.prepare_query_value(op, v) for v in value]
|
||||
|
@ -1462,6 +1462,27 @@ class QuerySetTest(unittest.TestCase):
|
||||
|
||||
Number.drop_collection()
|
||||
|
||||
def test_unset_reference(self):
|
||||
class Comment(Document):
|
||||
text = StringField()
|
||||
|
||||
class Post(Document):
|
||||
comment = ReferenceField(Comment)
|
||||
|
||||
Comment.drop_collection()
|
||||
Post.drop_collection()
|
||||
|
||||
comment = Comment.objects.create(text='test')
|
||||
post = Post.objects.create(comment=comment)
|
||||
|
||||
self.assertEqual(post.comment, comment)
|
||||
Post.objects.update(unset__comment=1)
|
||||
post.reload()
|
||||
self.assertEqual(post.comment, None)
|
||||
|
||||
Comment.drop_collection()
|
||||
Post.drop_collection()
|
||||
|
||||
|
||||
class QTest(unittest.TestCase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user