【发布时间】:2021-12-15 03:40:28
【问题描述】:
我有一个接受帖子标签列表的 GraphQL 突变。 PostTag 模型是:
model PostTag {
id BigInt @id @default(autoincrement())
order Int
value String
post Post @relation(fields: [postId], references: [id])
postId BigInt @map("post_id")
@@map("post_tag")
}
我的 REST API 是 PUT /posts/{postId}/tags,它接收要根据给定 Post 更新的标签列表。在这个列表中,一些标签可能有id,这意味着它是一个应该更新的现有tag 项目。会有tag 的项目没有id 的意思,应该是新添加的。给定帖子缺少标签意味着应该删除这些标签。
我可以使用 SQL 合并语句来做到这一点。我想使用 Prisma 获得类似的结果。如何使用 Prisma 有效地做到这一点?
【问题讨论】: