-
-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update and return model #637
Comments
I have the same problem/question. So far I am updating the records with, say Model, and right afterwards I do the selection:
which is awful but works. Aiming for better solutions! |
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I'm not sure if there's already a way to deal with it, but I couldn't find anything, so in case the functionality is implemented, it is not in the docs (or it's difficult to find it).
Describe the solution you'd like
In my case I'm using fastapi to update a model, call it
myModel
, which hasM2M
relations. In particular, I need to update the values of the fields inmyModel
and theM2M
relations. I would like to update the fields and get the newly updated object, on which I can remove/add theM2M
relations.Describe alternatives you've considered
await myModel.get(id=id).update(
**input.dict(exclude_unset=True)
)
model = await myModel.get(id=id).prefetch_related("other_relation", "another_relation")
[model.other_relation.remove(x) for x in model.other_relations]
for id in other_rel_ids:
await model.other_relation.add(Other_relation.get(id=id))
In this case I need to execute the update query, then get the model and only then start updating the
M2M
relations. When tables are small it does not influence much performances, but for bigger tables it becomes a problem. Is there a way to update and get the model with the updated fields at once?Additional context
Python: 3.8.5
Tortoise-orm: 0.16.20
The text was updated successfully, but these errors were encountered: