next.js 在Prisma中的多个条件下删除

iezvtpos  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(43)

所以我理解Prisma中的where子句需要一个 unique 输入来运行它的delete,但是我已经使用了@@unique函数来确保 multiple 条件需要是唯一的。我正在努力理解的是当涉及到删除功能时如何实现这一点。

model CommentDislike {
  id         Int      @id @default(autoincrement())
  comment    Comment  @relation(fields: [comment_id], references: [id], onDelete: Cascade)
  comment_id Int
  user       User     @relation(fields: [user_id], references: [id], onDelete: Cascade)
  user_id    String
  created_at DateTime @default(now())

  @@unique([user_id, comment_id])
}

个字符
这不起作用。想使用AND子句,但这也不起作用。

tquggr8v

tquggr8v1#

如果你有一个复合id,你可以通过提供两者来删除,如下所述:https://www.prisma.io/docs/orm/prisma-client/special-fields-and-types/working-with-composite-ids-and-constraints#deleting-records-by-a-compound-id-or-unique-constraint

const commentDislike = await prisma.commentDislike.delete({
  where: {
    userId_commentId: {
      userId: 1,
      commentId: 1,
    },
  },
})

字符串

相关问题