3.0 KiB
models.mixins.prefetch_mixin
PrefetchQueryMixin Objects
class PrefetchQueryMixin(RelationMixin)
Used in PrefetchQuery to extract ids and names of models to prefetch.
get_clause_target_and_filter_column_name
| @staticmethod
| get_clause_target_and_filter_column_name(parent_model: Type["Model"], target_model: Type["Model"], reverse: bool, related: str) -> Tuple[Type["Model"], str]
Returns Model on which query clause should be performed and name of the column.
Arguments:
parent_model (Type[Model]): related model that the relation lead totarget_model (Type[Model]): model on which query should be perfomedreverse (bool): flag if the relation is reverserelated (str): name of the relation field
Returns:
(Tuple[Type[Model], str]): Model on which query clause should be performed and name of the column
get_column_name_for_id_extraction
| @staticmethod
| get_column_name_for_id_extraction(parent_model: Type["Model"], reverse: bool, related: str, use_raw: bool) -> str
Returns name of the column that should be used to extract ids from model. Depending on the relation side it's either primary key column of parent model or field name specified by related parameter.
Arguments:
parent_model (Type[Model]): model from which id column should be extractedreverse (bool): flag if the relation is reverserelated (str): name of the relation fielduse_raw (bool): flag if aliases or field names should be used
Returns:
():
get_related_field_name
| @classmethod
| get_related_field_name(cls, target_field: Type["ForeignKeyField"]) -> str
Returns name of the relation field that should be used in prefetch query. This field is later used to register relation in prefetch query, populate relations dict, and populate nested model in prefetch query.
Arguments:
target_field (Type[BaseField]): relation field that should be used in prefetch
Returns:
(str): name of the field
get_filtered_names_to_extract
| @classmethod
| get_filtered_names_to_extract(cls, prefetch_dict: Dict) -> List
Returns list of related fields names that should be followed to prefetch related models from.
List of models is translated into dict to assure each model is extracted only once in one query, that's why this function accepts prefetch_dict not list.
Only relations from current model are returned.
Arguments:
prefetch_dict (Dict): dictionary of fields to extract
Returns:
(List): list of fields names to extract