diff --git a/AUTHORS b/AUTHORS index 3955a551..274fe1e9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -76,3 +76,4 @@ that much better: * Adam Parrish * jpfarias * jonrscott + * Alice Zoƫ Bevan-McGregor diff --git a/docs/changelog.rst b/docs/changelog.rst index 977a568f..4acc8c17 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,7 @@ Changelog Changes in dev ============== +- Fixed dereferencing - multi directional list dereferencing - Fixed issue creating indexes with recursive embedded documents - Fixed recursive lookup in _unique_with_indexes - Fixed passing ComplexField defaults to constructor for ReferenceFields diff --git a/mongoengine/dereference.py b/mongoengine/dereference.py index 4e595b19..0d8d7f15 100644 --- a/mongoengine/dereference.py +++ b/mongoengine/dereference.py @@ -168,9 +168,9 @@ class DeReference(object): elif isinstance(v, (dict, pymongo.son.SON)) and '_ref' in v: data[k]._data[field_name] = self.object_map.get(v['_ref'].id, v) elif isinstance(v, dict) and depth <= self.max_depth: - data[k]._data[field_name] = self._attach_objects(v, depth - 1, instance=instance, name=name) + data[k]._data[field_name] = self._attach_objects(v, depth, instance=instance, name=name) elif isinstance(v, (list, tuple)) and depth <= self.max_depth: - data[k]._data[field_name] = self._attach_objects(v, depth - 1, instance=instance, name=name) + data[k]._data[field_name] = self._attach_objects(v, depth, instance=instance, name=name) elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth: data[k] = self._attach_objects(v, depth - 1, instance=instance, name=name) elif hasattr(v, 'id'): diff --git a/tests/dereference.py b/tests/dereference.py index 2e24a61e..88cf17ee 100644 --- a/tests/dereference.py +++ b/tests/dereference.py @@ -760,3 +760,26 @@ class FieldTest(unittest.TestCase): UserB.drop_collection() UserC.drop_collection() Group.drop_collection() + + def test_multidirectional_lists(self): + + class Asset(Document): + name = StringField(max_length=250, required=True) + parent = GenericReferenceField(default=None) + parents = ListField(GenericReferenceField()) + children = ListField(GenericReferenceField()) + + Asset.drop_collection() + + root = Asset(name='', path="/", title="Site Root") + root.save() + + company = Asset(name='company', title='Company', parent=root, parents=[root]) + company.save() + + root.children = [company] + root.save() + + root = root.reload() + self.assertEquals(root.children, [company]) + self.assertEquals(company.parents, [root])