When checking out the typings for the update method in Prisma ORM, I found that I can only include a where clause for unique fields:
return this.prisma.publication.update({
data,
where: {id},
});
I'd love to combine this with authentication and do something like:
return this.prisma.publication.update({
data,
where: {id, owner: user.id}, <-- Authorisation
});
Is this at all possible with Prisma or do I need a separate query for this that retrieves the instance?
In this case, you would need to use updateMany as you are using a non-unique field along with the unique one.
Apparently, as of Prisma version 4.5.0, there is a new feature allowing you to add non-unique fields to the unique where clause as long it contains at least one unique field.
Prisma realese 4.5.0
It's a preview feature so in order to enable it, add this to your shcema.prisma:
generator js {
provider = "prisma-client-js"
previewFeatures = ["extendedWhereUnique"]
}
And then your code sample will work.
return this.prisma.publication.update({
data,
where: {id, owner: user.id},
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With