Files
ormar/docs/api/models/mixins/relation-mixin.md

2.3 KiB

models.mixins.relation_mixin

RelationMixin Objects

class RelationMixin()

Used to return relation fields/names etc. from given model

extract_db_own_fields

 | @classmethod
 | extract_db_own_fields(cls) -> Set

Returns only fields that are stored in the own database table, exclude all related fields.

Returns:

(Set): set of model fields with relation fields excluded

 | @classmethod
 | extract_related_fields(cls) -> List

Returns List of ormar Fields for all relations declared on a model. List is cached in cls._related_fields for quicker access.

Returns:

(List): list of related fields

 | @classmethod
 | extract_related_names(cls) -> Set

Returns List of fields names for all relations declared on a model. List is cached in cls._related_names for quicker access.

Returns:

(List): list of related fields names

 | @classmethod
 | _extract_db_related_names(cls) -> Set

Returns only fields that are stored in the own database table, exclude related fields that are not stored as foreign keys on given model.

Returns:

(Set): set of model fields with non fk relation fields excluded

 | @classmethod
 | _exclude_related_names_not_required(cls, nested: bool = False) -> Set

Returns a set of non mandatory related models field names.

For a main model (not nested) only nullable related field names are returned, for nested models all related models are returned.

Arguments:

  • nested (bool): flag setting nested models (child of previous one, not main one)

Returns:

(Set): set of non mandatory related fields