# relations.relation\_manager ## RelationsManager Objects ```python class RelationsManager() ``` Manages relations on a Model, each Model has it's own instance. #### \_\_contains\_\_ ```python | __contains__(item: str) -> bool ``` Checks if relation with given name is already registered. **Arguments**: - `item (str)`: name of attribute **Returns**: `(bool)`: result of the check #### get ```python | get(name: str) -> Optional[Union["Model", Sequence["Model"]]] ``` Returns the related model/models if relation is set. Actual call is delegated to Relation instance registered under relation name. **Arguments**: - `name (str)`: name of the relation **Returns**: `(Optional[Union[Model, List[Model]])`: related model or list of related models if set #### add ```python | @staticmethod | add(parent: "Model", child: "Model", field: "ForeignKeyField") -> None ``` Adds relation on both sides -> meaning on both child and parent models. One side of the relation is always weakref proxy to avoid circular refs. Based on the side from which relation is added and relation name actual names of parent and child relations are established. The related models are registered on both ends. **Arguments**: - `parent (Model)`: parent model on which relation should be registered - `child (Model)`: child model to register - `field (ForeignKeyField)`: field with relation definition #### remove ```python | remove(name: str, child: Union["NewBaseModel", Type["NewBaseModel"]]) -> None ``` Removes given child from relation with given name. Since you can have many relations between two models you need to pass a name of relation from which you want to remove the child. **Arguments**: - `name (str)`: name of the relation - `child (Union[Model, Type[Model]])`: child to remove from relation #### remove\_parent ```python | @staticmethod | remove_parent(item: Union["NewBaseModel", Type["NewBaseModel"]], parent: "Model", name: str) -> None ``` Removes given parent from relation with given name. Since you can have many relations between two models you need to pass a name of relation from which you want to remove the parent. **Arguments**: - `item (Union[Model, Type[Model]])`: model with parent registered - `parent (Model)`: parent Model - `name (str)`: name of the relation #### \_get ```python | _get(name: str) -> Optional[Relation] ``` Returns the actual relation and not the related model(s). **Arguments**: - `name (str)`: name of the relation **Returns**: `(ormar.relations.relation.Relation)`: Relation instance #### \_get\_relation\_type ```python | _get_relation_type(field: "BaseField") -> RelationType ``` Returns type of the relation declared on a field. **Arguments**: - `field (BaseField)`: field with relation declaration **Returns**: `(RelationType)`: type of the relation defined on field #### \_add\_relation ```python | _add_relation(field: "BaseField") -> None ``` Registers relation in the manager. Adds Relation instance under field.name. **Arguments**: - `field (BaseField)`: field with relation declaration