MCPcopy
hub / github.com/ormar-orm/ormar / expand_reverse_relationships

Function expand_reverse_relationships

ormar/models/helpers/relations.py:91–109  ·  view source on GitHub ↗

Iterates through model_fields of given model and verifies if all reverse relation have been populated on related models. If the reverse relation has not been set before it's set here. :param model: model on which relation should be checked and registered :type model: Model cla

(model: type["Model"])

Source from the content-addressed store, hash-verified

89
90
91def expand_reverse_relationships(model: type["Model"]) -> None:
92 """
93 Iterates through model_fields of given model and verifies if all reverse
94 relation have been populated on related models.
95
96 If the reverse relation has not been set before it's set here.
97
98 :param model: model on which relation should be checked and registered
99 :type model: Model class
100 """
101 model_fields = list(model.ormar_config.model_fields.values())
102 for model_field in model_fields:
103 if (
104 model_field.is_relation
105 and not model_field.has_unresolved_forward_refs()
106 and not model_field.is_through
107 ):
108 model_field = cast("ForeignKeyField", model_field)
109 expand_reverse_relationship(model_field=model_field)
110
111
112def register_reverse_model_fields(model_field: "ForeignKeyField") -> None:

Callers 1

__new__Method · 0.90

Calls 3

valuesMethod · 0.45

Tested by

no test coverage detected