Faizan
07/28/2021, 6:59 AMmodel Campaign {
id String @id @default(uuid())
company Company @relation(fields: [companyId], references: [id])
companyId String
}
model Company {
id String @id @default(uuid())
Campaign Campaign[]
}
------------------
await prisma.campaign.updateMany({
where: { id: campaignId, companyId },
data: { ...data }
});
I have to query campaign by it's ID but I also use company ID(which is authenticated) to match and verify that the campaign belongs to the authorized company rather than just updating it.
But I have to use updateMany
instead of update
because update does not support more than one argument in the where.
I need to the updated object as the return value which is available in update
which I can not use due to the above limitation. Is there a workaround for this? Thanks.Ryan
07/28/2021, 10:20 AMupdate
.Faizan
07/28/2021, 10:41 AMFaizan
07/28/2021, 1:31 PMmodel User {
favorites : String[]
}
Is there a way to add if not exists and remove if it does via Prisma?
If not, then is there a way to remove a value from the array? (I believe pop is used to add)Ryan
07/28/2021, 1:42 PMpush
is used to add but that doesn’t check if it exists. In that case, you need 2 queries: to fetch the value first, add/remove items and then update with the latest value.Faizan
07/28/2021, 1:44 PM