Skip to content

Commit ef6793c

Browse files
committed
proofread and fix the docs for relations
1 parent 8598de4 commit ef6793c

File tree

6 files changed

+18
-29
lines changed

6 files changed

+18
-29
lines changed

docs/relations/foreign-key.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ But you cannot:
4545

4646
* Access the related field from reverse model with `related_name`
4747
* Even if you `select_related` from reverse side of the model the returned models won't be populated in reversed instance (the join is not prevented so you still can `filter` and `order_by` over the relation)
48-
* The relation won't be populated in `model_dump()` and `json()`
48+
* The relation won't be populated in `model_dump()` and `model_dump_json()`
4949
* You cannot pass the nested related objects when populating from dictionary or json (also through `fastapi`). It will be either ignored or error will be raised depending on `extra` setting in pydantic `Config`.
5050

5151
Example:
@@ -110,7 +110,7 @@ assert department.courses[0] == course
110110
!!!warning
111111
If you want to add child model on related model the primary key value for parent model **has to exist in database**.
112112

113-
Otherwise ormar will raise RelationshipInstanceError as it cannot set child's ForeignKey column value
113+
Otherwise ormar will raise `RelationshipInstanceError` as it cannot set child's ForeignKey column value
114114
if parent model has no primary key value.
115115

116116
That means that in example above the department has to be saved before you can call `department.courses.add()`.
@@ -149,7 +149,7 @@ await department.courses.remove(course, keep_reversed=False)
149149

150150
Removal of all related models in one call.
151151

152-
Like remove by default `clear()` nulls the ForeigKey column on child model (all, not matter if they are loaded or not).
152+
Like with remove, by default, `clear()` nulls the ForeigKey column on child model (all, not matter if they are loaded or not).
153153

154154
```python
155155
# nulls department column on all courses related to this department
@@ -171,7 +171,7 @@ To read which methods of QuerySet are available read below [querysetproxy][query
171171

172172
## related_name
173173

174-
But you can overwrite this name by providing `related_name` parameter like below:
174+
You can overwrite related model field name by providing `related_name` parameter like below:
175175

176176
```Python hl_lines="27-29 35"
177177
--8<-- "../docs_src/fields/docs002.py"

docs/relations/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The definition of one-to-many relation also uses `ForeignKey`, and it's register
2626

2727
So in relation to example above.
2828

29-
```Python hl_lines="8"
29+
```Python hl_lines="7-8"
3030
class Department(ormar.Model):
3131
ormar_config = base_ormar_config.copy()
3232

@@ -50,7 +50,7 @@ class Department(ormar.Model):
5050

5151
To define many-to-many relation use `ManyToMany` field.
5252

53-
```python hl_lines="18"
53+
```python hl_lines="19"
5454
class Category(ormar.Model):
5555
ormar_config = ormar.OrmarConfig(
5656
database=database,
@@ -91,7 +91,7 @@ side of the current query for m2m models.
9191
So if you query from model `A` to model `B`, only model `B` has through field exposed.
9292
Which kind of make sense, since it's a one through model/field for each of related models.
9393

94-
```python hl_lines="12-20"
94+
```python hl_lines="12-21"
9595
class Category(ormar.Model):
9696
ormar_config = ormar.OrmarConfig(
9797
database=database,

docs/relations/many-to-many.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ news = await Category.objects.create(name="News")
2424

2525
`ForeignKey` fields are automatically registering reverse side of the relation.
2626

27-
By default it's child (source) `Model` name + s, like courses in snippet below:
27+
By default it's child (source) `Model` name + s, like `posts` in snippet below:
2828

29-
```python
29+
```python hl_lines="25-26"
3030
class Category(ormar.Model):
3131
ormar_config = base_ormar_config.copy(tablename="categories")
3232

@@ -79,12 +79,14 @@ categories: Optional[Union[Category, List[Category]]] = ormar.ManyToMany(
7979
If you are sure you don't want the reverse relation you can use `skip_reverse=True`
8080
flag of the `ManyToMany`.
8181

82-
If you set `skip_reverse` flag internally the field is still registered on the other
83-
side of the relationship so you can:
82+
If you set `skip_reverse` flag internally the field is still registered on the other
83+
side of the relationship so you can:
84+
8485
* `filter` by related models fields from reverse model
8586
* `order_by` by related models fields from reverse model
8687

87-
But you cannot:
88+
But you cannot:
89+
8890
* access the related field from reverse model with `related_name`
8991
* even if you `select_related` from reverse side of the model the returned models won't be populated in reversed instance (the join is not prevented so you still can `filter` and `order_by` over the relation)
9092
* the relation won't be populated in `model_dump()` and `json()`

docs/relations/postponed-annotations.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,8 @@ First, you need to import the required ref from typing.
1414
from typing import ForwardRef
1515
```
1616

17-
But note that before python 3.7 it used to be internal, so for python <= 3.6 you need
18-
19-
```python
20-
from typing import _ForwardRef as ForwardRef
21-
```
22-
23-
or since `pydantic` is required by `ormar` it can handle this switch for you.
24-
In that case you can simply import ForwardRef from pydantic regardless of your python version.
25-
26-
```python
27-
from pydantic.typing import ForwardRef
28-
```
29-
3017
Now we need a sample model and a reference to the same model,
31-
which will be used to creat a self referencing relation.
18+
which will be used to create a self referencing relation.
3219

3320
```python
3421
# create the forwardref to model Person

docs/relations/queryset-proxy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ assert post.categories[0] == news
5858

5959
`get_or_create(_defaults: Optional[Dict[str, Any]] = None, **kwargs) -> Tuple[Model, bool]`
6060

61-
Tries to get a row meeting the criteria and if NoMatch exception is raised it creates a new one with given kwargs and _defaults.
61+
Tries to get a row meeting the criteria and if `NoMatch` exception is raised it creates a new one with given kwargs and _defaults.
6262

6363
!!!tip
6464
Read more in queries documentation [get_or_create][get_or_create]

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ nav:
1616
- Pydantic only fields: fields/pydantic-fields.md
1717
- Fields encryption: fields/encryption.md
1818
- Relations:
19-
- relations/index.md
20-
- relations/postponed-annotations.md
19+
- Relation types: relations/index.md
2120
- relations/foreign-key.md
2221
- relations/many-to-many.md
22+
- relations/postponed-annotations.md
2323
- relations/queryset-proxy.md
2424
- Queries:
2525
- queries/index.md

0 commit comments

Comments
 (0)