add tests for cross model forward references, add docs for processing forwardrefs, wip on refactoring queries into separate pages based on functionality
This commit is contained in:
@ -1,11 +1,30 @@
|
||||
<a name="fields.many_to_many"></a>
|
||||
# fields.many\_to\_many
|
||||
|
||||
<a name="fields.many_to_many.populate_m2m_params_based_on_to_model"></a>
|
||||
#### populate\_m2m\_params\_based\_on\_to\_model
|
||||
|
||||
```python
|
||||
populate_m2m_params_based_on_to_model(to: Type["Model"], nullable: bool) -> Tuple[Any, Any]
|
||||
```
|
||||
|
||||
Based on target to model to which relation leads to populates the type of the
|
||||
pydantic field to use and type of the target column field.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `to (Model class)`: target related ormar Model
|
||||
- `nullable (bool)`: marks field as optional/ required
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(tuple with target pydantic type and target col type)`: Tuple[List, Any]
|
||||
|
||||
<a name="fields.many_to_many.ManyToMany"></a>
|
||||
#### ManyToMany
|
||||
|
||||
```python
|
||||
ManyToMany(to: Type["Model"], through: Type["Model"], *, name: str = None, unique: bool = False, virtual: bool = False, **kwargs: Any) -> Any
|
||||
ManyToMany(to: Union[Type["Model"], ForwardRef], through: Union[Type["Model"], ForwardRef], *, name: str = None, unique: bool = False, virtual: bool = False, **kwargs: Any, ,) -> Any
|
||||
```
|
||||
|
||||
Despite a name it's a function that returns constructed ManyToManyField.
|
||||
@ -37,6 +56,22 @@ class ManyToManyField(ForeignKeyField, ormar.QuerySetProtocol, ormar.RelationP
|
||||
|
||||
Actual class returned from ManyToMany function call and stored in model_fields.
|
||||
|
||||
<a name="fields.many_to_many.ManyToManyField.get_source_related_name"></a>
|
||||
#### get\_source\_related\_name
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_source_related_name(cls) -> str
|
||||
```
|
||||
|
||||
Returns name to use for source relation name.
|
||||
For FK it's the same, differs for m2m fields.
|
||||
It's either set as `related_name` or by default it's field name.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(str)`: name of the related_name or default related name.
|
||||
|
||||
<a name="fields.many_to_many.ManyToManyField.default_target_field_name"></a>
|
||||
#### default\_target\_field\_name
|
||||
|
||||
@ -51,3 +86,51 @@ Returns default target model name on through model.
|
||||
|
||||
`(str)`: name of the field
|
||||
|
||||
<a name="fields.many_to_many.ManyToManyField.default_source_field_name"></a>
|
||||
#### default\_source\_field\_name
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| default_source_field_name(cls) -> str
|
||||
```
|
||||
|
||||
Returns default target model name on through model.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(str)`: name of the field
|
||||
|
||||
<a name="fields.many_to_many.ManyToManyField.has_unresolved_forward_refs"></a>
|
||||
#### has\_unresolved\_forward\_refs
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| has_unresolved_forward_refs(cls) -> bool
|
||||
```
|
||||
|
||||
Verifies if the filed has any ForwardRefs that require updating before the
|
||||
model can be used.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(bool)`: result of the check
|
||||
|
||||
<a name="fields.many_to_many.ManyToManyField.evaluate_forward_ref"></a>
|
||||
#### evaluate\_forward\_ref
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| evaluate_forward_ref(cls, globalns: Any, localns: Any) -> None
|
||||
```
|
||||
|
||||
Evaluates the ForwardRef to actual Field based on global and local namespaces
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `globalns (Any)`: global namespace
|
||||
- `localns (Any)`: local namespace
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(None)`: None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user