Fixed EmbeddedDocuments with id
also storing _id
(#402)
This commit is contained in:
parent
6c599ef506
commit
d593f7e04b
@ -262,6 +262,8 @@ class BaseDocument(object):
|
|||||||
data[field.db_field] = value
|
data[field.db_field] = value
|
||||||
|
|
||||||
# If "_id" has not been set, then try and set it
|
# If "_id" has not been set, then try and set it
|
||||||
|
Document = _import_class("Document")
|
||||||
|
if isinstance(self, Document):
|
||||||
if data["_id"] is None:
|
if data["_id"] is None:
|
||||||
data["_id"] = self._data.get("id", None)
|
data["_id"] = self._data.get("id", None)
|
||||||
|
|
||||||
|
@ -444,6 +444,13 @@ class InstanceTest(unittest.TestCase):
|
|||||||
self.assertEqual(Employee(name="Bob", age=35, salary=0).to_mongo().keys(),
|
self.assertEqual(Employee(name="Bob", age=35, salary=0).to_mongo().keys(),
|
||||||
['_cls', 'name', 'age', 'salary'])
|
['_cls', 'name', 'age', 'salary'])
|
||||||
|
|
||||||
|
def test_embedded_document_to_mongo_id(self):
|
||||||
|
class SubDoc(EmbeddedDocument):
|
||||||
|
id = StringField(required=True)
|
||||||
|
|
||||||
|
sub_doc = SubDoc(id="abc")
|
||||||
|
self.assertEqual(sub_doc.to_mongo().keys(), ['id'])
|
||||||
|
|
||||||
def test_embedded_document(self):
|
def test_embedded_document(self):
|
||||||
"""Ensure that embedded documents are set up correctly.
|
"""Ensure that embedded documents are set up correctly.
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user