【问题标题】:Retrieving related model of a deleted model in Prisma 2在 Prisma 2 中检索已删除模型的相关模型
【发布时间】:2020-11-18 08:59:19
【问题描述】:

大家好,这里是我的场景;

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。” 知道我该如何解决吗? 谢谢

【问题讨论】:

    标签: prisma-graphql nexus-prisma prisma2


    【解决方案1】:
    猜你喜欢
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 2020-12-10
    相关资源
    最近更新 更多