【问题标题】:Problem with Schema Model type when using PrismaJS and NestJS使用 PrismaJS 和 NestJS 时模式模型类型的问题
【发布时间】:2021-11-03 15:22:31
【问题描述】:

我的 Prisma 架构中有 Members 模型,如下所示:

其中branch 是与具有branchId 外键的Branch 模型的关系。

我在会员服务中使用此架构,如下所示:

lastBranchFromMember 在哪里返回用户并在选择中填充了 branch。 当我想访问控制器中的分支名称但 branch 在控制器中无法识别时会出现问题,我只能在输入 lastBranchFromMember.branch.name 时选择 branchIdbranchOrder

我在我的 Prisma Schema 中做错了吗?还是我必须做其他事情?

感谢您的帮助。

在这里,我附上了导出的 prisma 客户端文件,用于 branch 不存在但仍然可以使用 { include: { branch: true }} 访问的成员我很困惑

【问题讨论】:

    标签: postgresql nestjs prisma


    【解决方案1】:

    需要使用{ include: { branch: true } },返回类型不正确。应该是这样的:

    import { Prisma } from '@prisma/client'
    
    type MemberWithBranch = Prisma.MemberGetPayload<{
      include: { branch: true }
    }>
    
    async lastBranchFromMember(branchId: string): Promise<MemberWithBranch> {
      // function
    }
    

    【讨论】:

    • 我以为是自动添加的 Promise
    • 没有。 Member 不包含 branch。你需要像上面那样添加一个类型。
    猜你喜欢
    • 2020-06-16
    • 2023-04-06
    • 1970-01-01
    • 2015-02-17
    • 2021-01-09
    • 1970-01-01
    • 2018-10-22
    • 2011-02-19
    • 1970-01-01
    相关资源
    最近更新 更多