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

Method create_through_instance

ormar/relations/querysetproxy.py:116–136  ·  view source on GitHub ↗

Crete a through model instance in the database for m2m relations. :param kwargs: dict of additional keyword arguments for through instance :type kwargs: Any :param child: child model instance :type child: Model

(self, child: "T", **kwargs: Any)

Source from the content-addressed store, hash-verified

114 self.relation.remove(item)
115
116 async def create_through_instance(self, child: "T", **kwargs: Any) -> None:
117 """
118 Crete a through model instance in the database for m2m relations.
119
120 :param kwargs: dict of additional keyword arguments for through instance
121 :type kwargs: Any
122 :param child: child model instance
123 :type child: Model
124 """
125 model_cls = self.relation.through
126 owner_column = self.related_field.default_target_field_name() # type: ignore
127 child_column = self.related_field.default_source_field_name() # type: ignore
128 rel_kwargs = {owner_column: self._owner.pk, child_column: child.pk}
129 final_kwargs = {**rel_kwargs, **kwargs}
130 if child.pk is None:
131 raise ModelPersistenceError(
132 f"You cannot save {child.get_name()} "
133 f"model without primary key set! \n"
134 f"Save the child model first."
135 )
136 await model_cls(**final_kwargs).save()
137
138 async def update_through_instance(self, child: "T", **kwargs: Any) -> None:
139 """

Callers 3

createMethod · 0.95
addMethod · 0.80

Calls 5

get_nameMethod · 0.80
saveMethod · 0.80

Tested by

no test coverage detected