Reference field

Work with references.

class RDoc(Document):
    i = fields.IntegerField()

class Doc(Document):
    rdoc = fields.ReferenceField(RDoc)

rdoc = RDoc()
rdoc.i = 13

doc = Doc()
doc.rdoc = rdoc

doc = db.get_queryset(Doc).find_one(  # reload doc
assert ==
assert doc.rdoc.i == 13

Or asynchronous:

rdoc = await doc.rdoc
assert ==
assert rdoc.i == 13
assert doc.rdoc ==
exception yadm.fields.reference.BrokenReference

Raise if referrenced document is not found.

exception yadm.fields.reference.NotBindingToDatabase

Raise if set ObjectId insted referenced document to new document, who not binded to database.

class yadm.fields.reference.Reference(_id: bson.objectid.ObjectId, parent: yadm.documents.DocumentItemMixin, field: yadm.fields.reference.ReferenceField)

Reference object.

This is awaitable:

doc = await reference
class yadm.fields.reference.ReferenceField(reference_document_class, **kwargs)

Field for work with references.

Parameters:reference_document_class – class for refered documents
get_fake(document, faker, depth)

Try create referenced document.