```model Campaign {   id               String     ...
# orm-help
f
Copy code
model 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.
r
@Faizan 👋 The only workaround is to use 2 queries. One for verifying the company and then updating with
update
.
f
Thanks!
👍 1
hey @Ryan Another question.
Copy code
model 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)
r
push
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.
f
Alright. Thanks a lot for your quick reply! 😄
🙌 1