Remove WhereUnique constraint from single object lookups #10376
Labels
kind/feature
A request for a new feature.
team/client
Issue for team Client.
topic: client api
topic: prisma-client
Milestone
Problem
Single object lookups are constrained to unique fields. This affects the methods
create()
,update()
andfindOne()
. It is not possible to include non-unique fields in the lookup expression. Example:prisma.Post.delete({where: {id: 1, nonUniqueField: false}}) // this is not allowed
. This is a constraint that Prisma adds. This constraint does not exist in the underlying SQL. The ability to only include unique fields is a significant limitation for many professional use cases and bloats up the required code for many applications while only providing marginal benefits.Example: Most professional apps use a soft-delete feature. When retrieving an instance it is very common to check, if the instance was soft deleted. Desired syntax
prisma.Post.findUnique({where: {id: postId, isDeleted: false}})
.Current workarounds
id
for an update callprisma.Post.updateMany({where: category: "basic" })
(we now have to restore the database).This problem was discussed here and here. But no good argument was brought up as to why this limitation exists other than marginally better typings.
Suggested solution
Option 1: Single object lookups should accept unique and non-unique input. Single object lookups should throw an exception if more than one object is found which sufficiently guarantees correct behavior.
Option2: Add new methods
findOne
,createOne
... that accept non-unique input and return one instance.The text was updated successfully, but these errors were encountered: