MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / cascade_save

Method cascade_save

mongoengine/document.py:589–614  ·  view source on GitHub ↗

Recursively save any references and generic references on the document.

(self, **kwargs)

Source from the content-addressed store, hash-verified

587 return object_id, created
588
589 def cascade_save(self, **kwargs):
590 """Recursively save any references and generic references on the
591 document.
592 """
593 _refs = kwargs.get("_refs") or []
594
595 ReferenceField = _import_class("ReferenceField")
596 GenericReferenceField = _import_class("GenericReferenceField")
597
598 for name, cls in self._fields.items():
599 if not isinstance(cls, (ReferenceField, GenericReferenceField)):
600 continue
601
602 ref = self._data.get(name)
603 if not ref or isinstance(ref, DBRef):
604 continue
605
606 if not getattr(ref, "_changed_fields", True):
607 continue
608
609 ref_id = f"{ref.__class__.__name__},{str(ref._data)}"
610 if ref and ref_id not in _refs:
611 _refs.append(ref_id)
612 kwargs["_refs"] = _refs
613 ref.save(**kwargs)
614 ref._changed_fields = []
615
616 @property
617 def _qs(self):

Callers 1

saveMethod · 0.95

Calls 4

_import_classFunction · 0.90
itemsMethod · 0.80
getMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected