【问题标题】:Prisma: Update using "where" with non-unique fields?Prisma:使用具有非唯一字段的“where”进行更新?
【发布时间】:2021-08-05 22:54:07
【问题描述】:

在检查 Prisma ORM 中更新方法的类型时,我发现我只能为唯一字段包含 where 子句:

return this.prisma.publication.update({
    data,
    where: {id},
});

我很想将此与身份验证结合起来,并执行以下操作:

return this.prisma.publication.update({
    data,
    where: {id, owner: user.id}, <-- Authorisation
});

Prisma 是否可以做到这一点,还是我需要一个单独的查询来检索实例?

【问题讨论】:

    标签: node.js typescript prisma


    【解决方案1】:

    在这种情况下,您需要使用updateMany,因为您将非唯一字段与唯一字段一起使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 2012-01-06
      • 2022-12-17
      • 1970-01-01
      • 2013-04-16
      相关资源
      最近更新 更多