MCPcopy Create free account
hub / github.com/tortoise/tortoise-orm / ForeignKeyFieldInstance

Class ForeignKeyFieldInstance

tortoise/fields/relational.py:315–339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313
314
315class ForeignKeyFieldInstance(RelationalField[MODEL]):
316 def __init__(
317 self,
318 model_name: type[Model] | str,
319 related_name: str | None | Literal[False] = None,
320 on_delete: OnDelete = CASCADE,
321 **kwargs: Any,
322 ) -> None:
323 super().__init__(None, **kwargs) # type:ignore[arg-type]
324 self.validate_model_name(model_name)
325 self.model_name = model_name
326 self.related_name = related_name
327 if on_delete not in set(OnDelete):
328 raise ConfigurationError(
329 "on_delete can only be CASCADE, RESTRICT, SET_NULL, SET_DEFAULT or NO_ACTION"
330 )
331 if on_delete == SET_NULL and not bool(kwargs.get("null")):
332 raise ConfigurationError("If on_delete is SET_NULL, then field must have null=True set")
333 self.on_delete = on_delete
334
335 def describe(self, serializable: bool) -> dict:
336 desc = super().describe(serializable)
337 desc["raw_field"] = self.source_field
338 desc["on_delete"] = str(self.on_delete)
339 return desc
340
341
342class BackwardFKRelation(RelationalField[MODEL]):

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…