Commit b03ead92 authored by Yury's avatar Yury

document: allow returning none if related document doesnt exist

parent 88bf47c0
Pipeline #326 failed with stages
in 4 minutes and 47 seconds
......@@ -61,7 +61,7 @@ class DocumentField:
def __eq__(self, other: "DocumentField"):
try:
return self.document_cls is other.document_cls and self.name == other.name
return self.document_cls is other.document_cls and self.name == other.name
except AttributeError:
raise TypeError(f"Can't compare {other} to DocumentField.")
......@@ -316,12 +316,15 @@ class Document(metaclass=MetaDocument):
async def fget(self):
field = DocumentField(self.__class__, self_field)
if multiple:
return await other_field.document_cls.many(
**{other_field.name: self[field.name]})
else:
return await other_field.document_cls.one(
**{other_field.name: self[field.name]})
try:
if multiple:
return await other_field.document_cls.many(
**{other_field.name: self._document_.get(field.name)})
else:
return await other_field.document_cls.one(
**{other_field.name: self._document_.get(field.name)})
except DocumentDoesntExist:
return
result = property(fget=fget)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment