使用 PrismaJS 和 NestJS 时模式模型类型的问题
Problem with Schema Model type when using PrismaJS and NestJS
我的 Prisma 模式中有 Members 模型,如下所示:
其中 branch
是与具有 branchId
外键的 Branch 模型的关系。
我在会员服务中使用这个模式如下:
其中 lastBranchFromMember
returns 用户在 select 中填充了 分支 。
当我想在控制器中访问分支名称但 branch 在控制器中无法识别时出现问题,我只能 select branchId
或 branchOrder
当我输入 lastBranchFromMember.branch.name
我是不是在 Prisma Schema 中做错了什么?还是我必须做其他事情?
感谢您的帮助。
我在这里附上为成员导出的 prisma 客户端文件,其中 branch
不存在但仍然可以通过 { include: { branch: true }}
访问我很困惑
您需要使用{ include: { branch: true } }
并且return类型不正确。应该是这样的:
import { Prisma } from '@prisma/client'
type MemberWithBranch = Prisma.MemberGetPayload<{
include: { branch: true }
}>
async lastBranchFromMember(branchId: string): Promise<MemberWithBranch> {
// function
}
我的 Prisma 模式中有 Members 模型,如下所示:
其中 branch
是与具有 branchId
外键的 Branch 模型的关系。
我在会员服务中使用这个模式如下:
其中 lastBranchFromMember
returns 用户在 select 中填充了 分支 。
当我想在控制器中访问分支名称但 branch 在控制器中无法识别时出现问题,我只能 select branchId
或 branchOrder
当我输入 lastBranchFromMember.branch.name
我是不是在 Prisma Schema 中做错了什么?还是我必须做其他事情?
感谢您的帮助。
我在这里附上为成员导出的 prisma 客户端文件,其中 branch
不存在但仍然可以通过 { include: { branch: true }}
访问我很困惑
您需要使用{ include: { branch: true } }
并且return类型不正确。应该是这样的:
import { Prisma } from '@prisma/client'
type MemberWithBranch = Prisma.MemberGetPayload<{
include: { branch: true }
}>
async lastBranchFromMember(branchId: string): Promise<MemberWithBranch> {
// function
}