New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Allow non-unique fields to be used with update #12268
Comments
hey @capaj - thanks for the issue! Would a composite index over |
Yes it would, but sometimes the update is ok to be slower and we want to keep writes as fast as possible without updating an index. |
Hey @floelhoeffel, just want to second these issues around updates supporting non-unique attributes to filter by. IMO, the framework shouldn't encourage adding indexes when there doesn't need to be one. Arbitrary conditionals in a Let me provide a concrete example below to (hopefully) further motivate this request. We have a session object that can be revoked by setting its The solution instead seems to be to write two queries instead of one. One network request to find the object and one to then update it. There are two problems with this:
Transactions may be able to help with 2), but then we'd be adding even more code/complexity to what should otherwise just have been one simple |
Thanks, we are looking into this right now. Here is another issue with a lot more use cases and comments: #7290 |
+1 would love support on this, something like a findOne() but an updateOne() where the return type is the updated row |
Hey folks, A solution was implemented by prisma/prisma-engines#3281. It will be available in the next release under a new preview flag called If you have any feedback you'd like to give about this feature, please post it here #15837 (comment) Thanks for your patience, closing now 🙏. |
Was there any solution to this.. @Weakky For updatemany with non unique key is inserting a new row |
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:
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
The text was updated successfully, but these errors were encountered: