Hello there, I'm new here and got a (probably) dum...
# orm-help
m
Hello there, I'm new here and got a (probably) dumb question. I want to update a user with his ID (unique) and workspace (not unique, to verify if the user making this request has the same workspace in his token). So I'm making a where
{ id: 1, workspace: 1 }
, but got an error because we can only update where with "UniqueInput" keys. I guess this is not a bug but a choice, but is there any workaround to do what I want ?
m
Is this for Prisma 2? If so, you could use
updateMany
. I can't think of a reason why it would be an issue apart from the fact that you get a count of changed records back and not a the updated record:
Copy code
const changedCount = await prisma.user.updateMany({
    data: {
      name: "New name",
    },
    where: {
      id: 2,
      workspace: 10
    },
  });
(Prisma 1 has updateMany* as well, it seems)
m
Thanks for your reply. Yes this is for Prisma 2, I've tried updateMany, it worked well, but it returns only
count: 1
. I'm a little borring (😁), but is there any possibility to get the complete entity updated ?
m
That's fair - I understand your requirement. At the moment you can't get the updated record back without issuing another
findOne
query after the update returns.
m
Okay got it, thanks
m
No problemo, thanks for raising the use case! I'll pass your use case along; alternatively you can add a GitHub issue prisma so that others with similar scenarios can chime in.
👍 1
r
Or you could use findMany before the update