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

Method object

mongoengine/document.py:1125–1141  ·  view source on GitHub ↗

Lazy-load the object referenced by ``self.key``. ``self.key`` should be the ``primary_key``.

(self)

Source from the content-addressed store, hash-verified

1123
1124 @property
1125 def object(self):
1126 """Lazy-load the object referenced by ``self.key``. ``self.key``
1127 should be the ``primary_key``.
1128 """
1129 id_field = self._document()._meta["id_field"]
1130 id_field_type = type(id_field)
1131
1132 if not isinstance(self.key, id_field_type):
1133 try:
1134 self.key = id_field_type(self.key)
1135 except Exception:
1136 raise Exception("Could not cast key as %s" % id_field_type.__name__)
1137
1138 if not hasattr(self, "_key_object"):
1139 self._key_object = self._document.objects.with_id(self.key)
1140 return self._key_object
1141 return self._key_object

Callers

nothing calls this directly

Calls 1

with_idMethod · 0.80

Tested by

no test coverage detected