This commit is contained in:
collerek
2021-06-08 14:34:02 +02:00
parent a1557273b0
commit 96c9615229
49 changed files with 1917 additions and 994 deletions

View File

@ -14,12 +14,12 @@ order_by parameters was set.
**Arguments**:
- `models (List[tests.test_prefetch_related.Division])`: list of models already fetched from db
- `orders_by (Dict[str, str])`: order by dictionary
- `models` (`List[tests.test_prefetch_related.Division]`): list of models already fetched from db
- `orders_by` (`Dict[str, str]`): order by dictionary
**Returns**:
`(List[tests.test_prefetch_related.Division])`: sorted list of models
`List[tests.test_prefetch_related.Division]`: sorted list of models
<a name="queryset.prefetch_query.set_children_on_model"></a>
#### set\_children\_on\_model
@ -39,12 +39,12 @@ Also relation is registered as each child is set as parent related field name va
**Arguments**:
- `model (Model)`: parent model instance
- `related (str)`: name of the related field
- `children (Dict[int, set])`: dictionary of children ids/ related field value
- `model_id (int)`: id of the model on which children should be set
- `models (Dict)`: dictionary of child models instances
- `orders_by (Dict)`: order_by dictionary
- `model` (`Model`): parent model instance
- `related` (`str`): name of the related field
- `children` (`Dict[int, set]`): dictionary of children ids/ related field value
- `model_id` (`int`): id of the model on which children should be set
- `models` (`Dict`): dictionary of child models instances
- `orders_by` (`Dict`): order_by dictionary
<a name="queryset.prefetch_query.PrefetchQuery"></a>
## PrefetchQuery Objects
@ -74,12 +74,12 @@ Returns list with related models already prefetched and set.
**Arguments**:
- `models (List[Model])`: list of already instantiated models from main query
- `rows (List[sqlalchemy.engine.result.RowProxy])`: row sql result of the main query before the prefetch
- `models` (`List[Model]`): list of already instantiated models from main query
- `rows` (`List[sqlalchemy.engine.result.RowProxy]`): row sql result of the main query before the prefetch
**Returns**:
`(List[Model])`: list of models with children prefetched
`List[Model]`: list of models with children prefetched
<a name="queryset.prefetch_query.PrefetchQuery._extract_ids_from_raw_data"></a>
#### \_extract\_ids\_from\_raw\_data
@ -93,12 +93,12 @@ prefixed column name.
**Arguments**:
- `parent_model (Type[Model])`: ormar model class
- `column_name (str)`: name of the relation column which is a key column
- `parent_model` (`Type[Model]`): ormar model class
- `column_name` (`str`): name of the relation column which is a key column
**Returns**:
`(set)`: set of ids of related model that should be extracted
`set`: set of ids of related model that should be extracted
<a name="queryset.prefetch_query.PrefetchQuery._extract_ids_from_preloaded_models"></a>
#### \_extract\_ids\_from\_preloaded\_models
@ -112,12 +112,12 @@ in the original query before.
**Arguments**:
- `parent_model (Type["Model"])`: model from which related ids should be extracted
- `column_name (str)`: name of the relation column which is a key column
- `parent_model` (`Type["Model"]`): model from which related ids should be extracted
- `column_name` (`str`): name of the relation column which is a key column
**Returns**:
`(set)`: set of ids of related model that should be extracted
`set`: set of ids of related model that should be extracted
<a name="queryset.prefetch_query.PrefetchQuery._extract_required_ids"></a>
#### \_extract\_required\_ids
@ -131,13 +131,13 @@ or from already populated models.
**Arguments**:
- `parent_model (Type["Model"])`: model from which related ids should be extracted
- `reverse (bool)`: flag if the relation is reverse
- `related (str)`: name of the field with relation
- `parent_model` (`Type["Model"]`): model from which related ids should be extracted
- `reverse` (`bool`): flag if the relation is reverse
- `related` (`str`): name of the field with relation
**Returns**:
`(set)`: set of ids of related model that should be extracted
`set`: set of ids of related model that should be extracted
<a name="queryset.prefetch_query.PrefetchQuery._get_filter_for_prefetch"></a>
#### \_get\_filter\_for\_prefetch
@ -153,14 +153,14 @@ If there are no ids for relation the empty list is returned.
**Arguments**:
- `parent_model (Type["Model"])`: model from which related ids should be extracted
- `target_model (Type["Model"])`: model to which relation leads to
- `reverse (bool)`: flag if the relation is reverse
- `related (str)`: name of the field with relation
- `parent_model` (`Type["Model"]`): model from which related ids should be extracted
- `target_model` (`Type["Model"]`): model to which relation leads to
- `reverse` (`bool`): flag if the relation is reverse
- `related` (`str`): name of the field with relation
**Returns**:
`(List[sqlalchemy.sql.elements.TextClause])`:
`List[sqlalchemy.sql.elements.TextClause]`:
<a name="queryset.prefetch_query.PrefetchQuery._populate_nested_related"></a>
#### \_populate\_nested\_related
@ -174,13 +174,13 @@ included in prefetch query.
**Arguments**:
- `model (Model)`: ormar model instance
- `prefetch_dict (Dict)`: dictionary of models to prefetch
- `orders_by (Dict)`: dictionary of order bys
- `model` (`Model`): ormar model instance
- `prefetch_dict` (`Dict`): dictionary of models to prefetch
- `orders_by` (`Dict`): dictionary of order bys
**Returns**:
`(Model)`: model with children populated
`Model`: model with children populated
<a name="queryset.prefetch_query.PrefetchQuery._prefetch_related_models"></a>
#### \_prefetch\_related\_models
@ -201,12 +201,12 @@ on each of the parent models from list.
**Arguments**:
- `models (List[Model])`: list of parent models from main query
- `rows (List[sqlalchemy.engine.result.RowProxy])`: raw response from sql query
- `models` (`List[Model]`): list of parent models from main query
- `rows` (`List[sqlalchemy.engine.result.RowProxy]`): raw response from sql query
**Returns**:
`(List[Model])`: list of models with prefetch children populated
`List[Model]`: list of models with prefetch children populated
<a name="queryset.prefetch_query.PrefetchQuery._extract_related_models"></a>
#### \_extract\_related\_models
@ -225,17 +225,17 @@ Calls itself recurrently to extract deeper nested relations of related model.
**Arguments**:
- `related (str)`: name of the relation
- `target_model (Type[Model])`: model to which relation leads to
- `prefetch_dict (Dict)`: prefetch related list converted into dictionary
- `select_dict (Dict)`: select related list converted into dictionary
- `fields (Union[Set[Any], Dict[Any, Any], None])`: fields to include
- `exclude_fields (Union[Set[Any], Dict[Any, Any], None])`: fields to exclude
- `orders_by (Dict)`: dictionary of order bys clauses
- `related` (`str`): name of the relation
- `target_model` (`Type[Model]`): model to which relation leads to
- `prefetch_dict` (`Dict`): prefetch related list converted into dictionary
- `select_dict` (`Dict`): select related list converted into dictionary
- `fields` (`Union[Set[Any], Dict[Any, Any], None]`): fields to include
- `exclude_fields` (`Union[Set[Any], Dict[Any, Any], None]`): fields to exclude
- `orders_by` (`Dict`): dictionary of order bys clauses
**Returns**:
`(None)`: None
`None`: None
<a name="queryset.prefetch_query.PrefetchQuery._run_prefetch_query"></a>
#### \_run\_prefetch\_query
@ -252,12 +252,12 @@ models.
**Arguments**:
- `target_field ("BaseField")`: ormar field with relation definition
- `filter_clauses (List[sqlalchemy.sql.elements.TextClause])`: list of clauses, actually one clause with ids of relation
- `target_field` (`"BaseField"`): ormar field with relation definition
- `filter_clauses` (`List[sqlalchemy.sql.elements.TextClause]`): list of clauses, actually one clause with ids of relation
**Returns**:
`(Tuple[str, List])`: table prefix and raw rows from sql response
`Tuple[str, List]`: table prefix and raw rows from sql response
<a name="queryset.prefetch_query.PrefetchQuery._get_select_related_if_apply"></a>
#### \_get\_select\_related\_if\_apply
@ -272,12 +272,12 @@ deeper on related model and already loaded in select related query.
**Arguments**:
- `related (str)`: name of the relation
- `select_dict (Dict)`: dictionary of select related models in main query
- `related` (`str`): name of the relation
- `select_dict` (`Dict`): dictionary of select related models in main query
**Returns**:
`(Dict)`: dictionary with nested related of select related
`Dict`: dictionary with nested related of select related
<a name="queryset.prefetch_query.PrefetchQuery._update_already_loaded_rows"></a>
#### \_update\_already\_loaded\_rows
@ -290,9 +290,9 @@ Updates models that are already loaded, usually children of children.
**Arguments**:
- `target_field ("BaseField")`: ormar field with relation definition
- `prefetch_dict (Dict)`: dictionaries of related models to prefetch
- `orders_by (Dict)`: dictionary of order by clauses by model
- `target_field` (`"BaseField"`): ormar field with relation definition
- `prefetch_dict` (`Dict`): dictionaries of related models to prefetch
- `orders_by` (`Dict`): dictionary of order by clauses by model
<a name="queryset.prefetch_query.PrefetchQuery._populate_rows"></a>
#### \_populate\_rows
@ -312,11 +312,11 @@ and set on the parent model after sorting if needed.
**Arguments**:
- `excludable (ExcludableItems)`: structure of fields to include and exclude
- `rows (List[sqlalchemy.engine.result.RowProxy])`: raw sql response from the prefetch query
- `target_field ("BaseField")`: field with relation definition from parent model
- `parent_model (Type[Model])`: model with relation definition
- `table_prefix (str)`: prefix of the target table from current relation
- `prefetch_dict (Dict)`: dictionaries of related models to prefetch
- `orders_by (Dict)`: dictionary of order by clauses by model
- `excludable` (`ExcludableItems`): structure of fields to include and exclude
- `rows` (`List[sqlalchemy.engine.result.RowProxy]`): raw sql response from the prefetch query
- `target_field` (`"BaseField"`): field with relation definition from parent model
- `parent_model` (`Type[Model]`): model with relation definition
- `table_prefix` (`str`): prefix of the target table from current relation
- `prefetch_dict` (`Dict`): dictionaries of related models to prefetch
- `orders_by` (`Dict`): dictionary of order by clauses by model