Wlad Paiva
07/27/2021, 12:50 AMset
to save the changes between two implict many-to-many relationship and it was working great but as soon as I changed it to explicit which will basically save the order between the other two models, it stop worked.
model ModifiersOnItem {
item MenuItem @relation(fields: [itemId], references: [id])
itemId String
group MenuModifierGroup @relation(fields: [groupId], references: [id])
groupId String
order Int
@@id([itemId, groupId])
}
The set
doesn’t reflect the same functionality which is ok but now I’m wondering what would be the best approach for this scenario? Where do I have to update the relation between them and the order?
Should I delete all records and add new set again?
Something like this, would be cool to have:
const item = await prisma.menuItem.update({
where: {
id: params.id,
},
data: {
...data,
modifiers: {
set: [
{
// groupId: '',
// order: ''
},
],
},
},
})
Ryan
07/27/2021, 6:39 AMWlad Paiva
07/28/2021, 1:22 AMmodel MenuModifierGroup {
id String @id @default(uuid())
name String
title String
...
menuItems ModifiersOnItem[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model MenuItem {
id String @id @default(uuid())
name String @db.VarChar(40)
...
modifiers ModifiersOnItem[]
}
Ryan
07/29/2021, 2:30 PMprisma.menuItem.update({
where: {
id: 'params.id',
},
data: {
modifiers: {
set: {
itemId_groupId: {
groupId: '',
itemId: ''
}
}
}
}
})