fix for not saving related model in reverse rel

This commit is contained in:
collerek
2021-06-02 13:05:10 +02:00
parent 0254abcd6c
commit c8ca6edb22
5 changed files with 63 additions and 2 deletions

View File

@ -99,7 +99,7 @@ course = Course(name="Math", completed=False) # note - not saved
await department.courses.add(course)
assert course.pk is not None # child model was saved
# relation on child model is set and FK column saved in db
assert courses.department == department
assert course.department == department
# relation on parent model is also set
assert department.courses[0] == course
```
@ -112,6 +112,10 @@ assert department.courses[0] == course
That means that in example above the department has to be saved before you can call `department.courses.add()`.
!!!warning
This method will not work on `ManyToMany` relations - there, both sides of the relation have to be saved before adding to relation.
### remove
Removal of the related model one by one.

View File

@ -8,10 +8,13 @@
## 🐛 Fixes
* Fix is null filter with pagination and relations (by @erichaydel) [#214](https://github.com/collerek/ormar/issues/214)
* Fix not saving child object on reverse side of the relation if not saved before [#216](https://github.com/collerek/ormar/issues/216)
## 💬 Other
* Expand [fastapi](https://collerek.github.io/ormar/fastapi) part of the documentation to show samples of using ormar in requests and responses in fastapi.
* Improve the docs in regard of `default`, `ForeignKey.add` etc.
# 0.10.9