Fixed dereference issue with embedded listfield referencefields (#439)
This commit is contained in:
parent
2cd722d751
commit
661398d891
@ -4,6 +4,7 @@ Changelog
|
||||
|
||||
Changes in 0.8.4
|
||||
================
|
||||
- Fixed dereference issue with embedded listfield referencefields (#439)
|
||||
- Fixed slice when using inheritance causing fields to be excluded (#437)
|
||||
- Fixed ._get_db() attribute after a Document.switch_db() (#441)
|
||||
- Dynamic Fields store and recompose Embedded Documents / Documents correctly (#449)
|
||||
|
@ -4,7 +4,7 @@ from base import (BaseDict, BaseList, TopLevelDocumentMetaclass, get_document)
|
||||
from fields import (ReferenceField, ListField, DictField, MapField)
|
||||
from connection import get_db
|
||||
from queryset import QuerySet
|
||||
from document import Document
|
||||
from document import Document, EmbeddedDocument
|
||||
|
||||
|
||||
class DeReference(object):
|
||||
@ -33,7 +33,8 @@ class DeReference(object):
|
||||
self.max_depth = max_depth
|
||||
doc_type = None
|
||||
|
||||
if instance and isinstance(instance, (Document, TopLevelDocumentMetaclass)):
|
||||
if instance and isinstance(instance, (Document, EmbeddedDocument,
|
||||
TopLevelDocumentMetaclass)):
|
||||
doc_type = instance._fields.get(name)
|
||||
if hasattr(doc_type, 'field'):
|
||||
doc_type = doc_type.field
|
||||
|
@ -1171,6 +1171,30 @@ class FieldTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(2, len([brand for bg in brand_groups for brand in bg.brands]))
|
||||
|
||||
def test_dereferencing_embedded_listfield_referencefield(self):
|
||||
class Tag(Document):
|
||||
meta = {'collection': 'tags'}
|
||||
name = StringField()
|
||||
|
||||
class Post(EmbeddedDocument):
|
||||
body = StringField()
|
||||
tags = ListField(ReferenceField("Tag", dbref=True))
|
||||
|
||||
class Page(Document):
|
||||
meta = {'collection': 'pages'}
|
||||
tags = ListField(ReferenceField("Tag", dbref=True))
|
||||
posts = ListField(EmbeddedDocumentField(Post))
|
||||
|
||||
Tag.drop_collection()
|
||||
Page.drop_collection()
|
||||
|
||||
tag = Tag(name='test').save()
|
||||
post = Post(body='test body', tags=[tag])
|
||||
Page(tags=[tag], posts=[post]).save()
|
||||
|
||||
page = Page.objects.first()
|
||||
self.assertEqual(page.tags[0], page.posts[0].tags[0])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user