mdocument.model.relations.RelationManyToOne

class mdocument.model.relations.RelationManyToOne(parent_field: mdocument.model.field.Field, child_field: mdocument.model.field.Field)

Bases: mdocument.model.relations.Relation

Multiple parents one child.

This means that child field type is a tuple. Updates child field when parent updates. Deletion happens when all parents are deleted.

__init__(parent_field: mdocument.model.field.Field, child_field: mdocument.model.field.Field)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(parent_field, child_field)

Initialize self.

create_index()

Creates index for relation.

delete(client, document[, session])

Deletes child with only one parent.

get_collections(client)

Gets parent and child connection.

register(parent_field, child_field)

Saves relation to Model relations map.

update(client, document[, session])

Updates child fields from parent.

Attributes

child_document_cls

child_model

parent_document_cls

parent_model

abstract async create_index()

Creates index for relation.

async delete(client: AsyncIOMotorClient, document: MDocument, session=None)

Deletes child with only one parent. And removes parent from children.

get_collections(client) → Tuple[AsyncIOMotorCollection, AsyncIOMotorCollection]

Gets parent and child connection.

classmethod register(parent_field: Union[mdocument.model.field.Field, Type[mdocument.document.MDocument], Type[mdocument.model.model.Model]], child_field: mdocument.model.field.Field)

Saves relation to Model relations map.

async update(client, document, session=None)

Updates child fields from parent.