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

@ -23,13 +23,13 @@ complex relation prefixes if needed and nested groups also resolved.
**Arguments**:
- `model_cls (Type["Model"])`: model from which the query is run
- `select_related (List[str])`: list of models to join
- `filter_clauses (List[FilterAction])`: list of filter conditions
- `model_cls` (`Type["Model"]`): model from which the query is run
- `select_related` (`List[str]`): list of models to join
- `filter_clauses` (`List[FilterAction]`): list of filter conditions
**Returns**:
`(Tuple[List[FilterAction], List[str]])`: list of filter conditions and select_related list
`Tuple[List[FilterAction], List[str]]`: list of filter conditions and select_related list
<a name="queryset.clause.FilterGroup._iter"></a>
#### \_iter
@ -42,7 +42,7 @@ Iterates all actions in a tree
**Returns**:
`(Generator)`: generator yielding from own actions and nested groups
`Generator`: generator yielding from own actions and nested groups
<a name="queryset.clause.FilterGroup._get_text_clauses"></a>
#### \_get\_text\_clauses
@ -55,7 +55,7 @@ Helper to return list of text queries from actions and nested groups
**Returns**:
`(List[sqlalchemy.sql.elements.TextClause])`: list of text queries from actions and nested groups
`List[sqlalchemy.sql.elements.TextClause]`: list of text queries from actions and nested groups
<a name="queryset.clause.FilterGroup.get_text_clause"></a>
#### get\_text\_clause
@ -72,7 +72,7 @@ Compiles the clause.
**Returns**:
`(sqlalchemy.sql.elements.TextClause)`: complied and escaped clause
`sqlalchemy.sql.elements.TextClause`: complied and escaped clause
<a name="queryset.clause.or_"></a>
#### or\_
@ -85,12 +85,12 @@ Construct or filter from nested groups and keyword arguments
**Arguments**:
- `args (Tuple[FilterGroup])`: nested filter groups
- `kwargs (Any)`: fields names and proper value types
- `args` (`Tuple[FilterGroup]`): nested filter groups
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup ready to be resolved
`ormar.queryset.clause.FilterGroup`: FilterGroup ready to be resolved
<a name="queryset.clause.and_"></a>
#### and\_
@ -103,12 +103,12 @@ Construct and filter from nested groups and keyword arguments
**Arguments**:
- `args (Tuple[FilterGroup])`: nested filter groups
- `kwargs (Any)`: fields names and proper value types
- `args` (`Tuple[FilterGroup]`): nested filter groups
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup ready to be resolved
`ormar.queryset.clause.FilterGroup`: FilterGroup ready to be resolved
<a name="queryset.clause.QueryClause"></a>
## QueryClause Objects
@ -132,12 +132,12 @@ mentioned in select_related strings but not included in select_related.
**Arguments**:
- `_own_only ()`:
- `kwargs (Any)`: key, value pair with column names and values
- `_own_only`:
- `kwargs` (`Any`): key, value pair with column names and values
**Returns**:
`(Tuple[List[sqlalchemy.sql.elements.TextClause], List[str]])`: Tuple with list of where clauses and updated select_related list
`Tuple[List[sqlalchemy.sql.elements.TextClause], List[str]]`: Tuple with list of where clauses and updated select_related list
<a name="queryset.clause.QueryClause._populate_filter_clauses"></a>
#### \_populate\_filter\_clauses
@ -152,11 +152,11 @@ is determined and the final clause is escaped if needed and compiled.
**Arguments**:
- `kwargs (Any)`: key, value pair with column names and values
- `kwargs` (`Any`): key, value pair with column names and values
**Returns**:
`(Tuple[List[sqlalchemy.sql.elements.TextClause], List[str]])`: Tuple with list of where clauses and updated select_related list
`Tuple[List[sqlalchemy.sql.elements.TextClause], List[str]]`: Tuple with list of where clauses and updated select_related list
<a name="queryset.clause.QueryClause._register_complex_duplicates"></a>
#### \_register\_complex\_duplicates
@ -173,11 +173,11 @@ model and whole relation key (not just last relation name).
**Arguments**:
- `select_related (List[str])`: list of relation strings
- `select_related` (`List[str]`): list of relation strings
**Returns**:
`(None)`: None
`None`: None
<a name="queryset.clause.QueryClause._parse_related_prefixes"></a>
#### \_parse\_related\_prefixes
@ -190,11 +190,11 @@ Walks all relation strings and parses the target models and prefixes.
**Arguments**:
- `select_related (List[str])`: list of relation strings
- `select_related` (`List[str]`): list of relation strings
**Returns**:
`(List[Prefix])`: list of parsed prefixes
`List[Prefix]`: list of parsed prefixes
<a name="queryset.clause.QueryClause._switch_filter_action_prefixes"></a>
#### \_switch\_filter\_action\_prefixes
@ -208,11 +208,11 @@ present in alias_manager.
**Arguments**:
- `filter_clauses (List[FilterAction])`: raw list of actions
- `filter_clauses` (`List[FilterAction]`): raw list of actions
**Returns**:
`(List[FilterAction])`: list of actions with aliases changed if needed
`List[FilterAction]`: list of actions with aliases changed if needed
<a name="queryset.clause.QueryClause._verify_prefix_and_switch"></a>
#### \_verify\_prefix\_and\_switch
@ -225,5 +225,5 @@ Helper to switch prefix to complex relation one if required
**Arguments**:
- `action (ormar.queryset.actions.filter_action.FilterAction)`: action to switch prefix in
- `action` (`ormar.queryset.actions.filter_action.FilterAction`): action to switch prefix in

View File

@ -22,7 +22,7 @@ Hack to avoid pydantic name check from parent model, returns false
**Returns**:
`(bool)`: False
`bool`: False
<a name="queryset.field_accessor.FieldAccessor.__getattr__"></a>
#### \_\_getattr\_\_
@ -36,11 +36,11 @@ Thanks to that operator overload is possible to use in filter.
**Arguments**:
- `item (str)`: attribute name
- `item` (`str`): attribute name
**Returns**:
`(ormar.queryset.field_accessor.FieldAccessor)`: FieldAccessor for field or nested model
`ormar.queryset.field_accessor.FieldAccessor`: FieldAccessor for field or nested model
<a name="queryset.field_accessor.FieldAccessor.__eq__"></a>
#### \_\_eq\_\_
@ -53,11 +53,11 @@ overloaded to work as sql `column = <VALUE>`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.__ge__"></a>
#### \_\_ge\_\_
@ -70,11 +70,11 @@ overloaded to work as sql `column >= <VALUE>`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.__gt__"></a>
#### \_\_gt\_\_
@ -87,11 +87,11 @@ overloaded to work as sql `column > <VALUE>`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.__le__"></a>
#### \_\_le\_\_
@ -104,11 +104,11 @@ overloaded to work as sql `column <= <VALUE>`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.__lt__"></a>
#### \_\_lt\_\_
@ -121,11 +121,11 @@ overloaded to work as sql `column < <VALUE>`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.__mod__"></a>
#### \_\_mod\_\_
@ -138,11 +138,11 @@ overloaded to work as sql `column LIKE '%<VALUE>%'`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.__lshift__"></a>
#### \_\_lshift\_\_
@ -155,11 +155,11 @@ overloaded to work as sql `column IN (<VALUE1>, <VALUE2>,...)`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.__rshift__"></a>
#### \_\_rshift\_\_
@ -172,11 +172,11 @@ overloaded to work as sql `column IS NULL`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.in_"></a>
#### in\_
@ -189,11 +189,11 @@ works as sql `column IN (<VALUE1>, <VALUE2>,...)`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.iexact"></a>
#### iexact
@ -206,11 +206,11 @@ works as sql `column = <VALUE>` case-insensitive
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.contains"></a>
#### contains
@ -223,11 +223,11 @@ works as sql `column LIKE '%<VALUE>%'`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.icontains"></a>
#### icontains
@ -240,11 +240,11 @@ works as sql `column LIKE '%<VALUE>%'` case-insensitive
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.startswith"></a>
#### startswith
@ -257,11 +257,11 @@ works as sql `column LIKE '<VALUE>%'`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.istartswith"></a>
#### istartswith
@ -274,11 +274,11 @@ works as sql `column LIKE '%<VALUE>'` case-insensitive
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.endswith"></a>
#### endswith
@ -291,11 +291,11 @@ works as sql `column LIKE '%<VALUE>'`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.iendswith"></a>
#### iendswith
@ -308,11 +308,11 @@ works as sql `column LIKE '%<VALUE>'` case-insensitive
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.isnull"></a>
#### isnull
@ -325,11 +325,11 @@ works as sql `column IS NULL` or `IS NOT NULL`
**Arguments**:
- `other (str)`: value to check agains operator
- `other` (`str`): value to check agains operator
**Returns**:
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
`ormar.queryset.clause.FilterGroup`: FilterGroup for operator
<a name="queryset.field_accessor.FieldAccessor.asc"></a>
#### asc
@ -342,7 +342,7 @@ works as sql `column asc`
**Returns**:
`(ormar.queryset.actions.OrderGroup)`: OrderGroup for operator
`ormar.queryset.actions.OrderGroup`: OrderGroup for operator
<a name="queryset.field_accessor.FieldAccessor.desc"></a>
#### desc
@ -355,5 +355,5 @@ works as sql `column desc`
**Returns**:
`(ormar.queryset.actions.OrderGroup)`: OrderGroup for operator
`ormar.queryset.actions.OrderGroup`: OrderGroup for operator

View File

@ -21,9 +21,9 @@ Applies all filter clauses if set.
**Arguments**:
- `expr (sqlalchemy.sql.selectable.Select)`: query to modify
- `expr` (`sqlalchemy.sql.selectable.Select`): query to modify
**Returns**:
`(sqlalchemy.sql.selectable.Select)`: modified query
`sqlalchemy.sql.selectable.Select`: modified query

View File

@ -20,7 +20,7 @@ Shortcut for ormar's model AliasManager stored on Meta.
**Returns**:
`(AliasManager)`: alias manager from model's Meta
`AliasManager`: alias manager from model's Meta
<a name="queryset.join.SqlJoin.to_table"></a>
#### to\_table
@ -34,7 +34,7 @@ Shortcut to table name of the next model
**Returns**:
`(str)`: name of the target table
`str`: name of the target table
<a name="queryset.join.SqlJoin._on_clause"></a>
#### \_on\_clause
@ -48,13 +48,13 @@ into one text clause used in joins.
**Arguments**:
- `previous_alias (str)`: alias of previous table
- `from_clause (str)`: from table name
- `to_clause (str)`: to table name
- `previous_alias` (`str`): alias of previous table
- `from_clause` (`str`): from table name
- `to_clause` (`str`): to table name
**Returns**:
`(sqlalchemy.text)`: clause combining all strings
`sqlalchemy.text`: clause combining all strings
<a name="queryset.join.SqlJoin.build_join"></a>
#### build\_join
@ -70,7 +70,7 @@ used_aliases and sort_orders.
**Returns**:
`(Tuple[List[str], Join, List[TextClause], collections.OrderedDict])`: list of used aliases, select from, list of aliased columns, sort orders
`Tuple[List[str], Join, List[TextClause], collections.OrderedDict]`: list of used aliases, select from, list of aliased columns, sort orders
<a name="queryset.join.SqlJoin._forward_join"></a>
#### \_forward\_join
@ -110,8 +110,8 @@ Updated are:
**Arguments**:
- `related_name (str)`: name of the relation to follow
- `remainder (Any)`: deeper tables if there are more nested joins
- `related_name` (`str`): name of the relation to follow
- `remainder` (`Any`): deeper tables if there are more nested joins
<a name="queryset.join.SqlJoin._process_m2m_through_table"></a>
#### \_process\_m2m\_through\_table
@ -147,11 +147,11 @@ Changes the same names in order_by queries if they are present.
**Arguments**:
- `reverse (bool)`: flag if it's on_clause lookup - use reverse fields
- `reverse` (`bool`): flag if it's on_clause lookup - use reverse fields
**Returns**:
`(str)`: new relation name switched to through model field
`str`: new relation name switched to through model field
<a name="queryset.join.SqlJoin._process_join"></a>
#### \_process\_join
@ -183,7 +183,7 @@ Verifies if proper field string is used.
**Arguments**:
- `order_by (str)`: string with order by definition
- `order_by` (`str`): string with order by definition
<a name="queryset.join.SqlJoin._get_alias_and_model"></a>
#### \_get\_alias\_and\_model
@ -196,11 +196,11 @@ Returns proper model and alias to be applied in the clause.
**Arguments**:
- `order_by (str)`: string with order by definition
- `order_by` (`str`): string with order by definition
**Returns**:
`(Tuple[str, Type["Model"]])`: alias and model to be used in clause
`Tuple[str, Type["Model"]]`: alias and model to be used in clause
<a name="queryset.join.SqlJoin._get_order_bys"></a>
#### \_get\_order\_bys
@ -225,5 +225,5 @@ different for ManyToMany relation, ForeignKey and reverse related of relations.
**Returns**:
`(Tuple[str, str])`: to key and from key
`Tuple[str, str]`: to key and from key

View File

@ -21,9 +21,9 @@ Applies the limit clause.
**Arguments**:
- `expr (sqlalchemy.sql.selectable.Select)`: query to modify
- `expr` (`sqlalchemy.sql.selectable.Select`): query to modify
**Returns**:
`(sqlalchemy.sql.selectable.Select)`: modified query
`sqlalchemy.sql.selectable.Select`: modified query

View File

@ -21,9 +21,9 @@ Applies the offset clause.
**Arguments**:
- `expr (sqlalchemy.sql.selectable.Select)`: query to modify
- `expr` (`sqlalchemy.sql.selectable.Select`): query to modify
**Returns**:
`(sqlalchemy.sql.selectable.Select)`: modified query
`sqlalchemy.sql.selectable.Select`: modified query

View File

@ -21,9 +21,9 @@ Applies all order_by clauses if set.
**Arguments**:
- `expr (sqlalchemy.sql.selectable.Select)`: query to modify
- `expr` (`sqlalchemy.sql.selectable.Select`): query to modify
**Returns**:
`(sqlalchemy.sql.selectable.Select)`: modified query
`sqlalchemy.sql.selectable.Select`: modified query

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

View File

@ -22,7 +22,7 @@ Shortcut to model class Meta set on QuerySet model.
**Returns**:
`(model Meta class)`: Meta class of the model
`model Meta class`: Meta class of the model
<a name="queryset.queryset.QuerySet.model"></a>
#### model
@ -36,7 +36,7 @@ Shortcut to model class set on QuerySet.
**Returns**:
`(Type[Model])`: model class
`Type[Model]`: model class
<a name="queryset.queryset.QuerySet.rebuild_self"></a>
#### rebuild\_self
@ -52,36 +52,36 @@ all not passed params are taken from current values.
#### \_prefetch\_related\_models
```python
| async _prefetch_related_models(models: List[Optional["T"]], rows: List) -> List[Optional["T"]]
| async _prefetch_related_models(models: List["T"], rows: List) -> List["T"]
```
Performs prefetch query for selected models names.
**Arguments**:
- `models (List[Model])`: list of already parsed main Models from main query
- `rows (List[sqlalchemy.engine.result.RowProxy])`: database rows from main query
- `models` (`List[Model]`): list of already parsed main Models from main query
- `rows` (`List[sqlalchemy.engine.result.RowProxy]`): database rows from main query
**Returns**:
`(List[Model])`: list of models with prefetch models populated
`List[Model]`: list of models with prefetch models populated
<a name="queryset.queryset.QuerySet._process_query_result_rows"></a>
#### \_process\_query\_result\_rows
```python
| _process_query_result_rows(rows: List) -> List[Optional["T"]]
| _process_query_result_rows(rows: List) -> List["T"]
```
Process database rows and initialize ormar Model from each of the rows.
**Arguments**:
- `rows (List[sqlalchemy.engine.result.RowProxy])`: list of database rows from query result
- `rows` (`List[sqlalchemy.engine.result.RowProxy]`): list of database rows from query result
**Returns**:
`(List[Model])`: list of models
`List[Model]`: list of models
<a name="queryset.queryset.QuerySet._resolve_filter_groups"></a>
#### \_resolve\_filter\_groups
@ -94,11 +94,11 @@ Resolves filter groups to populate FilterAction params in group tree.
**Arguments**:
- `groups (Any)`: tuple of FilterGroups
- `groups` (`Any`): tuple of FilterGroups
**Returns**:
`(Tuple[List[FilterGroup], List[str]])`: list of resolver groups
`Tuple[List[FilterGroup], List[str]]`: list of resolver groups
<a name="queryset.queryset.QuerySet.check_single_result_rows_count"></a>
#### check\_single\_result\_rows\_count
@ -112,7 +112,7 @@ Verifies if the result has one and only one row.
**Arguments**:
- `rows (List[Model])`: one element list of Models
- `rows` (`List[Model]`): one element list of Models
<a name="queryset.queryset.QuerySet.database"></a>
#### database
@ -126,7 +126,7 @@ Shortcut to models database from Meta class.
**Returns**:
`(databases.Database)`: database
`databases.Database`: database
<a name="queryset.queryset.QuerySet.table"></a>
#### table
@ -140,7 +140,7 @@ Shortcut to models table from Meta class.
**Returns**:
`(sqlalchemy.Table)`: database table
`sqlalchemy.Table`: database table
<a name="queryset.queryset.QuerySet.build_select_expression"></a>
#### build\_select\_expression
@ -154,13 +154,13 @@ If any of the params is not passed the QuerySet own value is used.
**Arguments**:
- `limit (int)`: number to limit the query
- `offset (int)`: number to offset by
- `order_bys (List)`: list of order-by fields names
- `limit` (`int`): number to limit the query
- `offset` (`int`): number to offset by
- `order_bys` (`List`): list of order-by fields names
**Returns**:
`(sqlalchemy.sql.selectable.Select)`: built sqlalchemy select expression
`sqlalchemy.sql.selectable.Select`: built sqlalchemy select expression
<a name="queryset.queryset.QuerySet.filter"></a>
#### filter
@ -190,14 +190,16 @@ You can use special filter suffix to change the filter operands:
* endswith - like `album__name__endswith='ibu'` (exact end match)
* iendswith - like `album__name__iendswith='IBU'` (case insensitive)
Note that you can also use python style filters - check the docs!
**Arguments**:
- `_exclude (bool)`: flag if it should be exclude or filter
- `kwargs (Any)`: fields names and proper value types
- `_exclude` (`bool`): flag if it should be exclude or filter
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(QuerySet)`: filtered QuerySet
`QuerySet`: filtered QuerySet
<a name="queryset.queryset.QuerySet.exclude"></a>
#### exclude
@ -220,11 +222,11 @@ becomes a union of conditions.
**Arguments**:
- `kwargs (Any)`: fields names and proper value types
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(QuerySet)`: filtered QuerySet
`QuerySet`: filtered QuerySet
<a name="queryset.queryset.QuerySet.select_related"></a>
#### select\_related
@ -245,11 +247,11 @@ To chain related `Models` relation use double underscores between names.
**Arguments**:
- `related (Union[List, str])`: list of relation field names, can be linked by '__' to nest
- `related` (`Union[List, str]`): list of relation field names, can be linked by '__' to nest
**Returns**:
`(QuerySet)`: QuerySet
`QuerySet`: QuerySet
<a name="queryset.queryset.QuerySet.select_all"></a>
#### select\_all
@ -272,13 +274,13 @@ Nested relations of those kind need to be loaded manually.
**Arguments**:
- `follow (bool)`: flag to trigger deep save -
by default only directly related models are saved
with follow=True also related models of related models are saved
- `follow` (`bool`): flag to trigger deep save -
**Returns**:
`(Model)`: reloaded Model
`Model`: reloaded Model
<a name="queryset.queryset.QuerySet.prefetch_related"></a>
#### prefetch\_related
@ -300,11 +302,11 @@ To chain related `Models` relation use double underscores between names.
**Arguments**:
- `related (Union[List, str])`: list of relation field names, can be linked by '__' to nest
- `related` (`Union[List, str]`): list of relation field names, can be linked by '__' to nest
**Returns**:
`(QuerySet)`: QuerySet
`QuerySet`: QuerySet
<a name="queryset.queryset.QuerySet.fields"></a>
#### fields
@ -351,12 +353,12 @@ To include whole nested model specify model related field name and ellipsis.
**Arguments**:
- `_is_exclude (bool)`: flag if it's exclude or include operation
- `columns (Union[List, str, Set, Dict])`: columns to include
- `_is_exclude` (`bool`): flag if it's exclude or include operation
- `columns` (`Union[List, str, Set, Dict]`): columns to include
**Returns**:
`(QuerySet)`: QuerySet
`QuerySet`: QuerySet
<a name="queryset.queryset.QuerySet.exclude_fields"></a>
#### exclude\_fields
@ -387,11 +389,11 @@ if explicitly excluded.
**Arguments**:
- `columns (Union[List, str, Set, Dict])`: columns to exclude
- `columns` (`Union[List, str, Set, Dict]`): columns to exclude
**Returns**:
`(QuerySet)`: QuerySet
`QuerySet`: QuerySet
<a name="queryset.queryset.QuerySet.order_by"></a>
#### order\_by
@ -427,11 +429,57 @@ To sort in descending order provide a hyphen in front of the field name
**Arguments**:
- `columns (Union[List, str])`: columns by which models should be sorted
- `columns` (`Union[List, str]`): columns by which models should be sorted
**Returns**:
`(QuerySet)`: QuerySet
`QuerySet`: QuerySet
<a name="queryset.queryset.QuerySet.values"></a>
#### values
```python
| async values(fields: Union[List, str, Set, Dict] = None, exclude_through: bool = False, _as_dict: bool = True, _flatten: bool = False) -> List
```
Return a list of dictionaries with column values in order of the fields
passed or all fields from queried models.
To filter for given row use filter/exclude methods before values,
to limit number of rows use limit/offset or paginate before values.
Note that it always return a list even for one row from database.
**Arguments**:
- `exclude_through` (`bool`): flag if through models should be excluded
- `_flatten` (`bool`): internal parameter to flatten one element tuples
- `_as_dict` (`bool`): internal parameter if return dict or tuples
- `fields` (`Union[List, str, Set, Dict]`): field name or list of field names to extract from db
<a name="queryset.queryset.QuerySet.values_list"></a>
#### values\_list
```python
| async values_list(fields: Union[List, str, Set, Dict] = None, flatten: bool = False, exclude_through: bool = False) -> List
```
Return a list of tuples with column values in order of the fields passed or
all fields from queried models.
When one field is passed you can flatten the list of tuples into list of values
of that single field.
To filter for given row use filter/exclude methods before values,
to limit number of rows use limit/offset or paginate before values.
Note that it always return a list even for one row from database.
**Arguments**:
- `exclude_through` (`bool`): flag if through models should be excluded
- `fields` (`Union[str, List[str]]`): field name or list of field names to extract from db
- `flatten` (`bool`): when one field is passed you can flatten the list of tuples
<a name="queryset.queryset.QuerySet.exists"></a>
#### exists
@ -445,7 +493,7 @@ Returns a bool value to confirm if there are rows matching the given criteria
**Returns**:
`(bool)`: result of the check
`bool`: result of the check
<a name="queryset.queryset.QuerySet.count"></a>
#### count
@ -459,7 +507,7 @@ Returns number of rows matching the given criteria
**Returns**:
`(int)`: number of rows
`int`: number of rows
<a name="queryset.queryset.QuerySet.max"></a>
#### max
@ -473,7 +521,7 @@ Returns max value of columns for rows matching the given criteria
**Returns**:
`(Any)`: max value of column(s)
`Any`: max value of column(s)
<a name="queryset.queryset.QuerySet.min"></a>
#### min
@ -487,7 +535,7 @@ Returns min value of columns for rows matching the given criteria
**Returns**:
`(Any)`: min value of column(s)
`Any`: min value of column(s)
<a name="queryset.queryset.QuerySet.sum"></a>
#### sum
@ -501,7 +549,7 @@ Returns sum value of columns for rows matching the given criteria
**Returns**:
`(int)`: sum value of columns
`int`: sum value of columns
<a name="queryset.queryset.QuerySet.avg"></a>
#### avg
@ -515,7 +563,7 @@ Returns avg value of columns for rows matching the given criteria
**Returns**:
`(Union[int, float, List])`: avg value of columns
`Union[int, float, List]`: avg value of columns
<a name="queryset.queryset.QuerySet.update"></a>
#### update
@ -531,12 +579,12 @@ each=True flag to affect whole table.
**Arguments**:
- `each (bool)`: flag if whole table should be affected if no filter is passed
- `kwargs (Any)`: fields names and proper value types
- `each` (`bool`): flag if whole table should be affected if no filter is passed
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(int)`: number of updated rows
`int`: number of updated rows
<a name="queryset.queryset.QuerySet.delete"></a>
#### delete
@ -552,12 +600,12 @@ each=True flag to affect whole table.
**Arguments**:
- `each (bool)`: flag if whole table should be affected if no filter is passed
- `kwargs (Any)`: fields names and proper value types
- `each` (`bool`): flag if whole table should be affected if no filter is passed
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(int)`: number of deleted rows
`int`: number of deleted rows
<a name="queryset.queryset.QuerySet.paginate"></a>
#### paginate
@ -571,12 +619,12 @@ Limit is set to page size and offset is set to (page-1) * page_size.
**Arguments**:
- `page_size (int)`: numbers of items per page
- `page (int)`: page number
- `page_size` (`int`): numbers of items per page
- `page` (`int`): page number
**Returns**:
`(QuerySet)`: QuerySet
`QuerySet`: QuerySet
<a name="queryset.queryset.QuerySet.limit"></a>
#### limit
@ -592,12 +640,12 @@ models use the `limit_raw_sql` parameter flag, and set it to `True`.
**Arguments**:
- `limit_raw_sql (bool)`: flag if raw sql should be limited
- `limit_count (int)`: number of models to limit
- `limit_raw_sql` (`bool`): flag if raw sql should be limited
- `limit_count` (`int`): number of models to limit
**Returns**:
`(QuerySet)`: QuerySet
`QuerySet`: QuerySet
<a name="queryset.queryset.QuerySet.offset"></a>
#### offset
@ -613,12 +661,12 @@ models use the `limit_raw_sql` parameter flag, and set it to `True`.
**Arguments**:
- `limit_raw_sql (bool)`: flag if raw sql should be offset
- `offset (int)`: numbers of models to offset
- `limit_raw_sql` (`bool`): flag if raw sql should be offset
- `offset` (`int`): numbers of models to offset
**Returns**:
`(QuerySet)`: QuerySet
`QuerySet`: QuerySet
<a name="queryset.queryset.QuerySet.first"></a>
#### first
@ -636,11 +684,11 @@ Gets the first row from the db ordered by primary key column ascending.
**Arguments**:
- `kwargs (Any)`: fields names and proper value types
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(Model)`: returned model
`Model`: returned model
<a name="queryset.queryset.QuerySet.get_or_none"></a>
#### get\_or\_none
@ -653,17 +701,18 @@ Get's the first row from the db meeting the criteria set by kwargs.
If no criteria set it will return the last row in db sorted by pk.
Passing a criteria is actually calling filter(**kwargs) method described below.
Passing a criteria is actually calling filter(*args, **kwargs) method described
below.
If not match is found None will be returned.
**Arguments**:
- `kwargs (Any)`: fields names and proper value types
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(Model)`: returned model
`Model`: returned model
<a name="queryset.queryset.QuerySet.get"></a>
#### get
@ -676,7 +725,8 @@ Get's the first row from the db meeting the criteria set by kwargs.
If no criteria set it will return the last row in db sorted by pk.
Passing a criteria is actually calling filter(**kwargs) method described below.
Passing a criteria is actually calling filter(*args, **kwargs) method described
below.
**Raises**:
@ -685,11 +735,11 @@ Passing a criteria is actually calling filter(**kwargs) method described below.
**Arguments**:
- `kwargs (Any)`: fields names and proper value types
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(Model)`: returned model
`Model`: returned model
<a name="queryset.queryset.QuerySet.get_or_create"></a>
#### get\_or\_create
@ -700,17 +750,20 @@ Passing a criteria is actually calling filter(**kwargs) method described below.
Combination of create and get methods.
Tries to get a row meeting the criteria fro kwargs
Tries to get a row meeting the criteria for kwargs
and if `NoMatch` exception is raised
it creates a new one with given kwargs.
Passing a criteria is actually calling filter(*args, **kwargs) method described
below.
**Arguments**:
- `kwargs (Any)`: fields names and proper value types
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(Model)`: returned or created Model
`Model`: returned or created Model
<a name="queryset.queryset.QuerySet.update_or_create"></a>
#### update\_or\_create
@ -723,32 +776,33 @@ Updates the model, or in case there is no match in database creates a new one.
**Arguments**:
- `kwargs (Any)`: fields names and proper value types
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(Model)`: updated or created model
`Model`: updated or created model
<a name="queryset.queryset.QuerySet.all"></a>
#### all
```python
| async all(*args: Any, **kwargs: Any) -> List[Optional["T"]]
| async all(*args: Any, **kwargs: Any) -> List["T"]
```
Returns all rows from a database for given model for set filter options.
Passing kwargs is a shortcut and equals to calling `filter(**kwrags).all()`.
Passing args and/or kwargs is a shortcut and equals to calling
`filter(*args, **kwargs).all()`.
If there are no rows meeting the criteria an empty list is returned.
**Arguments**:
- `kwargs (Any)`: fields names and proper value types
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(List[Model])`: list of returned models
`List[Model]`: list of returned models
<a name="queryset.queryset.QuerySet.create"></a>
#### create
@ -764,11 +818,11 @@ The allowed kwargs are `Model` fields names and proper value types.
**Arguments**:
- `kwargs (Any)`: fields names and proper value types
- `kwargs` (`Any`): fields names and proper value types
**Returns**:
`(Model)`: created model
`Model`: created model
<a name="queryset.queryset.QuerySet.bulk_create"></a>
#### bulk\_create
@ -787,7 +841,7 @@ Bulk operations do not send signals.
**Arguments**:
- `objects (List[Model])`: list of ormar models already initialized and ready to save.
- `objects` (`List[Model]`): list of ormar models already initialized and ready to save.
<a name="queryset.queryset.QuerySet.bulk_update"></a>
#### bulk\_update
@ -809,6 +863,6 @@ Bulk operations do not send signals.
**Arguments**:
- `objects (List[Model])`: list of ormar models
- `columns (List[str])`: list of columns to update
- `objects` (`List[Model]`): list of ormar models
- `columns` (`List[str]`): list of columns to update

View File

@ -51,7 +51,7 @@ at the end of whole query.
**Returns**:
`(bool)`: result of the check
`bool`: result of the check
<a name="queryset.query.Query.build_select_expression"></a>
#### build\_select\_expression
@ -70,7 +70,7 @@ Returns ready to run query with all joins and clauses.
**Returns**:
`(sqlalchemy.sql.selectable.Select)`: ready to run query with all joins and clauses.
`sqlalchemy.sql.selectable.Select`: ready to run query with all joins and clauses.
<a name="queryset.query.Query._build_pagination_condition"></a>
#### \_build\_pagination\_condition
@ -111,11 +111,11 @@ Returns complete ready to run query.
**Arguments**:
- `expr (sqlalchemy.sql.selectable.Select)`: select expression before clauses
- `expr` (`sqlalchemy.sql.selectable.Select`): select expression before clauses
**Returns**:
`(sqlalchemy.sql.selectable.Select)`: expresion with all present clauses applied
`sqlalchemy.sql.selectable.Select`: expresion with all present clauses applied
<a name="queryset.query.Query._reset_query_parameters"></a>
#### \_reset\_query\_parameters

View File

@ -0,0 +1,139 @@
<a name="queryset.reverse_alias_resolver"></a>
# queryset.reverse\_alias\_resolver
<a name="queryset.reverse_alias_resolver.ReverseAliasResolver"></a>
## ReverseAliasResolver Objects
```python
class ReverseAliasResolver()
```
Class is used to reverse resolve table aliases into relation strings
to parse raw data columns and replace table prefixes with full relation string
<a name="queryset.reverse_alias_resolver.ReverseAliasResolver.resolve_columns"></a>
#### resolve\_columns
```python
| resolve_columns(columns_names: List[str]) -> Dict
```
Takes raw query prefixed column and resolves the prefixes to
relation strings (relation names connected with dunders).
**Arguments**:
- `columns_names` (`List[str]`): list of column names with prefixes from query
**Returns**:
`Union[None, Dict[str, str]]`: dictionary of prefix: resolved names
<a name="queryset.reverse_alias_resolver.ReverseAliasResolver._resolve_column_with_prefix"></a>
#### \_resolve\_column\_with\_prefix
```python
| _resolve_column_with_prefix(column_name: str, prefix: str) -> None
```
Takes the prefixed column, checks if field should be excluded, and if not
it proceeds to replace prefix of a table with full relation string.
Sample: translates: "xsd12df_name" -> into: "posts__user__name"
**Arguments**:
- `column_name` (`str`): prefixed name of the column
- `prefix` (`str`): extracted prefix
<a name="queryset.reverse_alias_resolver.ReverseAliasResolver._check_if_field_is_excluded"></a>
#### \_check\_if\_field\_is\_excluded
```python
| _check_if_field_is_excluded(prefix: str, field: "ForeignKeyField", is_through: bool) -> bool
```
Checks if given relation is excluded in current query.
Note that in contrary to other queryset methods here you can exclude the
in-between models but keep the end columns, which does not make sense
when parsing the raw data into models.
So in relation category -> category_x_post -> post -> user you can exclude
category_x_post and post models but can keep the user one. (in ormar model
context that is not possible as if you would exclude through and post model
there would be no way to reach user model).
Exclusions happen on a model before the current one, so we need to move back
in chain of model by one or by two (m2m relations have through model in between)
**Arguments**:
- `prefix` (`str`): table alias
- `field` (`ForeignKeyField`): field with relation
- `is_through` (`bool`): flag if current table is a through table
**Returns**:
`bool`: result of the check
<a name="queryset.reverse_alias_resolver.ReverseAliasResolver._get_previous_excludable"></a>
#### \_get\_previous\_excludable
```python
| _get_previous_excludable(prefix: str, field: "ForeignKeyField", shift: int = 1) -> "Excludable"
```
Returns excludable related to model previous in chain of models.
Used to check if current model should be excluded.
**Arguments**:
- `prefix` (`str`): prefix of a current table
- `field` (`ForeignKeyField`): field with relation
- `shift` (`int`): how many model back to go - for m2m it's 2 due to through models
**Returns**:
`Excludable`: excludable for previous model
<a name="queryset.reverse_alias_resolver.ReverseAliasResolver._create_prefixes_map"></a>
#### \_create\_prefixes\_map
```python
| _create_prefixes_map() -> None
```
Creates a map of alias manager aliases keys to relation strings.
I.e in alias manager you can have alias user_roles: xas12ad
This method will create entry user_roles: roles, where roles is a name of
relation on user model.
Will also keep the relation field in separate dictionary so we can later
extract field names and owner models.
<a name="queryset.reverse_alias_resolver.ReverseAliasResolver._handle_through_fields_and_prefix"></a>
#### \_handle\_through\_fields\_and\_prefix
```python
| _handle_through_fields_and_prefix(model_cls: Type["Model"], field: "ForeignKeyField", previous_related_str: str, relation: str) -> str
```
Registers through models for m2m relations and switches prefix for
the one linking from through model to target model.
For other relations returns current model name + relation name as prefix.
Nested relations are a chain of relation names with __ in between.
**Arguments**:
- `model_cls` (`Type["Model"]`): model of current relation
- `field` (`ForeignKeyField`): field with relation
- `previous_related_str` (`str`): concatenated chain linked with "__"
- `relation` (`str`): name of the current relation in chain
**Returns**:
`str`: name of prefix to populate

View File

@ -16,13 +16,13 @@ All those checks verify if there is a need for deeper traversal.
**Arguments**:
- `part (str)`:
- `parts (List[str])`:
- `current_level (Any)`: current level of the traversed structure
- `part` (`str`):
- `parts` (`List[str]`):
- `current_level` (`Any`): current level of the traversed structure
**Returns**:
`(bool)`: result of the check
`bool`: result of the check
<a name="queryset.utils.translate_list_to_dict"></a>
#### translate\_list\_to\_dict
@ -39,13 +39,13 @@ Default required key ise Ellipsis like in pydantic.
**Arguments**:
- `list_to_trans (set)`: input list
- `is_order (bool)`: flag if change affects order_by clauses are they require special
default value with sort order.
- `list_to_trans` (`set`): input list
- `is_order` (`bool`): flag if change affects order_by clauses are they require special
**Returns**:
`(Dict)`: converted to dictionary input list
`Dict`: converted to dictionary input list
<a name="queryset.utils.convert_set_to_required_dict"></a>
#### convert\_set\_to\_required\_dict
@ -59,11 +59,11 @@ Required key is Ellipsis.
**Arguments**:
- `set_to_convert (set)`: set to convert to dict
- `set_to_convert` (`set`): set to convert to dict
**Returns**:
`(Dict)`: set converted to dict of ellipsis
`Dict`: set converted to dict of ellipsis
<a name="queryset.utils.update"></a>
#### update
@ -79,12 +79,12 @@ only other values are overwritten.
**Arguments**:
- `current_dict (Dict[str, ellipsis])`: dict to update
- `updating_dict (Dict)`: dict with values to update
- `current_dict` (`Dict[str, ellipsis]`): dict to update
- `updating_dict` (`Dict`): dict with values to update
**Returns**:
`(Dict)`: combination of both dicts
`Dict`: combination of both dicts
<a name="queryset.utils.subtract_dict"></a>
#### subtract\_dict
@ -100,12 +100,12 @@ only other values are overwritten.
**Arguments**:
- `current_dict (Dict[str, ellipsis])`: dict to update
- `updating_dict (Dict)`: dict with values to update
- `current_dict` (`Dict[str, ellipsis]`): dict to update
- `updating_dict` (`Dict`): dict with values to update
**Returns**:
`(Dict)`: combination of both dicts
`Dict`: combination of both dicts
<a name="queryset.utils.update_dict_from_list"></a>
#### update\_dict\_from\_list
@ -119,12 +119,12 @@ nested keys that are sets or dicts are combined and not overwritten.
**Arguments**:
- `curr_dict (Dict)`: dict to update
- `list_to_update (List[str])`: list with values to update the dict
- `curr_dict` (`Dict`): dict to update
- `list_to_update` (`List[str]`): list with values to update the dict
**Returns**:
`(Dict)`: updated dict
`Dict`: updated dict
<a name="queryset.utils.extract_nested_models"></a>
#### extract\_nested\_models
@ -144,10 +144,10 @@ Goes also into nested relations if needed (specified in select_dict).
**Arguments**:
- `model (Model)`: parent Model
- `model_type (Type[Model])`: parent model class
- `select_dict (Dict)`: dictionary of related models from select_related
- `extracted (Dict)`: dictionary with already extracted models
- `model` (`Model`): parent Model
- `model_type` (`Type[Model]`): parent model class
- `select_dict` (`Dict`): dictionary of related models from select_related
- `extracted` (`Dict`): dictionary with already extracted models
<a name="queryset.utils.extract_models_to_dict_of_lists"></a>
#### extract\_models\_to\_dict\_of\_lists
@ -162,14 +162,14 @@ with all children models under their relation keys.
**Arguments**:
- `model_type (Type[Model])`: parent model class
- `models (List[Model])`: list of models from which related models should be extracted.
- `select_dict (Dict)`: dictionary of related models from select_related
- `extracted (Dict)`: dictionary with already extracted models
- `model_type` (`Type[Model]`): parent model class
- `models` (`List[Model]`): list of models from which related models should be extracted.
- `select_dict` (`Dict`): dictionary of related models from select_related
- `extracted` (`Dict`): dictionary with already extracted models
**Returns**:
`(Dict)`: dictionary of lists f related models
`Dict`: dictionary of lists f related models
<a name="queryset.utils.get_relationship_alias_model_and_str"></a>
#### get\_relationship\_alias\_model\_and\_str
@ -183,12 +183,12 @@ constructed, extracts alias based on last relation leading to target model.
**Arguments**:
- `related_parts (Union[List, List[str]])`: list of related names extracted from string
- `source_model (Type[Model])`: model from which relation starts
- `related_parts` (`Union[List, List[str]]`): list of related names extracted from string
- `source_model` (`Type[Model]`): model from which relation starts
**Returns**:
`(Tuple[str, Type["Model"], str])`: table prefix, target model and relation string
`Tuple[str, Type["Model"], str]`: table prefix, target model and relation string
<a name="queryset.utils._process_through_field"></a>
#### \_process\_through\_field
@ -201,13 +201,13 @@ Helper processing through models as they need to be treated differently.
**Arguments**:
- `related_parts (List[str])`: split relation string
- `relation (str)`: relation name
- `related_field ("ForeignKeyField")`: field with relation declaration
- `previous_model (Type["Model"])`: model from which relation is coming
- `previous_models (List[Type["Model"]])`: list of already visited models in relation chain
- `related_parts` (`List[str]`): split relation string
- `relation` (`str`): relation name
- `related_field` (`"ForeignKeyField"`): field with relation declaration
- `previous_model` (`Type["Model"]`): model from which relation is coming
- `previous_models` (`List[Type["Model"]]`): list of already visited models in relation chain
**Returns**:
`(Tuple[Type["Model"], str, bool])`: previous_model, relation, is_through
`Tuple[Type["Model"], str, bool]`: previous_model, relation, is_through