Reputation: 520
I have Members model in my Prisma schema as follows:
where branch
is a relation to Branch model with branchId
foreign key.
I'm using this schema in members services as follows:
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
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
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