Adonis 4.1 - Update many tables at the same time. #1292
-
Hi, guys! I have many 1: N relationships. I know how to update 1 relationship at a time, now I tried to update many relationships at the same time, but it didn't work lol, and I tried it in many ways. Does anyone have an example of how to do this or where can I find it in the documentation? What I do is: A class has N phones, N addresses and belongs to a city. So, I don't know how to update all of this at the same time. I hope I have made it clear, I thank everyone who can help or criticize. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I'm not too sure what you are looking for? await ModelToUpdate.query().update({ phone: 123123).where('classAId', 10 }); |
Beta Was this translation helpful? Give feedback.
-
That's a late replay but better than nothing 😋
You already have property update there with merge and save and if property has multiple phones then how are they meant to be updated? If property has 10 phones, then how will you know which one was meant to be updated? |
Beta Was this translation helpful? Give feedback.
I'm not too sure what you are looking for?
Perhaps something like sync()? https://adonisjs.com/docs/4.1/relationships#_sync
Or just multi update? You can use bulk update for that: https://adonisjs.com/docs/4.0/lucid#_bulk_updates