question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Allow non-unique fields to be used with update

See original GitHub issue

Problem

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:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Weakkycommented, Oct 18, 2022

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 🙏.

2reactions
janpiocommented, Oct 1, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found