0

大家好,这是我的情况;

model User {
  id              Int               @default(autoincrement()) @id
  ...
  posts           Post[]
  comments        Comment[]
  
}
model Post {
  id          Int            @default(autoincrement()) @id
  comments    Comment[]
  ...
  
}
model Comment {
  id          Int               @default(autoincrement()) @id
  post        Post              @relation(fields: [postId], references: [id])
  postId      Int
  ...
}

所以我正在尝试删除评论,下面是我的方法

export const deleteComment = mutationField('deleteComment', {
    type: 'Comment',
    args: {
        where: 'CommentWhereUniqueInput',
    },
    resolve: async (_, { where }, ctx) => {
        let comment = await ctx.prisma.comment.delete({
            where: where,
            include:{
                author: true,
                post:true
            },
        })
      
        return comment
    },
})

但是我收到一条错误消息,上面写着“不能为不可为空的字段 Comment.post 返回 null。” 知道我该如何解决吗?谢谢

4

1 回答 1

2

也许与 npm i @paljs/plugins

https://paljs.com/plugins/delete/https://www.prisma.io/docs/guides/database-workflows/cascading-deletes/postgresql

于 2020-09-18T19:47:11.510 回答