rony
rony

Reputation: 520

Problem with Schema Model type when using PrismaJS and NestJS

I have Members model in my Prisma schema as follows: enter image description here

where branch is a relation to Branch model with branchId foreign key.

I'm using this schema in members services as follows: enter image description here

Where lastBranchFromMember returns user with populated branch in select. The problem occurs when I want to access branch name in controllers but branch doesn't get recognize in controllers, I can only select branchId or branchOrder when I type lastBranchFromMember.branch.name

enter image description here

Did I do something wrong in my Prisma Schema? or do I have to do something else?

Thank you for your help.

Here I attach exported prisma client file for Member where branch does not exists but still can be access with { include: { branch: true }} I'm confused

Upvotes: 0

Views: 223

Answers (1)

Ryan
Ryan

Reputation: 6327

You need to use { include: { branch: true } } and the return type is incorrect. It should be the following:

import { Prisma } from '@prisma/client'

type MemberWithBranch = Prisma.MemberGetPayload<{
  include: { branch: true }
}>

async lastBranchFromMember(branchId: string): Promise<MemberWithBranch> {
  // function
}

Upvotes: 1

Related Questions