How to use UpdateMany with multiple values #12254
-
|
Hey, how are y'all doing?! Let's say that I have a todo list and these todos can be placed inside groups, so I would have these two models: And each TodoGroup has a UP and DOWN arrow, to change their order on the frontend (react) and I also want to store the order inside the database to keep the UX consistent. How would I change the order of two TodoGroups at the same time? Because if I have a "TodoGroup A" with order: 1 and I click on DOWN arrow, I want the order to become 2, and the order of "TodoGroup B" becomes 1. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Hey @rodolphoasb 👋 await prisma.todoGroup.update({
where: {
order: 1,
},
data: { order: 2 },
});
await prisma.todoGroup.update({
where: {
order: 2,
},
data: { order: 1 },
}); Transactions can also be useful for your use case. |
Beta Was this translation helpful? Give feedback.
-
|
Hi there, To keep our discussions organized and focused on the most relevant topics, we’re reviewing and tidying up our backlog. As part of this process, we’re closing discussions that have already been marked as answered but remain open. If this discussion still requires further input or clarification, feel free to reopen it or start a new one with updated details. Your contributions are invaluable to the community, and we’re here to help! For more details about our priorities and vision for the future of Prisma ORM, check out our latest blog post: https://www.prisma.io/blog/prisma-orm-manifesto. Thank you for your understanding and ongoing support of the Prisma community! |
Beta Was this translation helpful? Give feedback.
Hey @rodolphoasb 👋
In this particular use case, I don't think the
updateManymethod would work.updateManyis for updating many records with the same data.For your use case, you would need to use two separate
updatecalls.Something like this:
Transactions can also be useful for your use case.