Is that possible to updateMany relation ? I want t...
# orm-help
r
Is that possible to updateMany relation ? I want to disassociate user from many chatroom with a single call.
prisma.chatroom.updateMany({ where: { founderId: { id} }, data: { members: { disconnect: {id: user.id}})
but the update many only allowed to change the chatroom property only.
👍 1
j
I could be wrong but I think you could update the other side of the relation to do this i.e. update the
user.chatrooms
r
Right now i use user.chatrooms, but I still need to find all the chatrooms owned by the chatroom founder to remove the user.
Copy code
const allChatrooms = await this.findAll(user);

const chatrooms = { disconnect: allChatrooms.map(chatroom => ({ id: chatroom.id })) };

await this.prisma.client.user.update({
 where: { id: userId },
 data: { chatrooms },
});
a
@James Homer, your answer helps me. Thank you.
👍 1