Feature: Allow non-unique fields to be used with update
See original GitHub issueProblem
when doing an update on a model sometime we want to filter on non-unique field to make sure that we only update rown which user has access to, for example like this:
prismaClient.userPicture.update({
where: {
id: picture.id,
user_id: req.user.id // currently this line is not possible when user_id is not unique
},
data: {
verified_at: new Date()
},
})
It would be nice to be able to optionally provide non unique fields to the where
condition.
Currently it only allows fiels which are unique.
I would like if we could use fields which are not unique as well.
Suggested solution
Allow non-unique fields to be used with update
.
Alternatives
Currently we can work around this by using updateMany
, but this is not ideal. In most API calls you want to return the updated item right away, so being able to do it all with a single prisma query would be nice.
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Prisma: Update using "where" with non-unique fields?
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...
Read more >Add a unique constraint to a field—ArcGIS Online Help
Layer owners or administrators can set unique constraints on fields in sublayers in hosted feature layers to ensure no duplicate values are stored...
Read more >Prevent duplicate values in a table field using an index
You can prevent duplicate values in a field in an Access table by creating a unique index. A unique index is an index...
Read more >Require unique values for a field
By default, fields are created without this constraint. A field can have unique values only if there are not already duplicate values in...
Read more >db.collection.update() — MongoDB Manual
Optional. An array of filter documents that determine which array elements to modify for an update operation on an array field. In the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey folks,
A solution was implemented by https://github.com/prisma/prisma-engines/pull/3281. It will be available in the next release under a new preview flag called
extendedWhereUnique
.If you have any feedback you’d like to give about this feature, please post it here https://github.com/prisma/prisma/issues/15837#event-7600630285
Thanks for your patience, closing now 🙏.
Thanks, we are looking into this right now.
Here is another issue with a lot more use cases and comments: https://github.com/prisma/prisma/issues/7290