Prisma is not returning a type that has the property for the included relation

Hello, I am using prisma to query some data from my database where the name of the relatonship is data so the final record object looks something like this
{
someThing1: string
someThing2: string
data: {
somethingRelated: string
}
}
{
someThing1: string
someThing2: string
data: {
somethingRelated: string
}
}
The record returned from Prisma has the data but is typed to look like
{
someThing1: string
someThing2: string
}
{
someThing1: string
someThing2: string
}
Any idea why this might be? Is there something I have to do to extend the type with the related model?
5 Replies
Leonidas
Leonidas3y ago
Show us your prisma schema please
Liam
LiamOP3y ago
model Member {
id String @id
email String @unique
name String
joinDate DateTime
checkins Checkin[]
data MemberData?
extendedMemberData String
}

model MemberData {
member Member? @relation(fields: [memberID], references: [id])
memberID String @id
major String?
classification String?
address String?
}
model Member {
id String @id
email String @unique
name String
joinDate DateTime
checkins Checkin[]
data MemberData?
extendedMemberData String
}

model MemberData {
member Member? @relation(fields: [memberID], references: [id])
memberID String @id
major String?
classification String?
address String?
}
and then the prisma query looks like
return await prisma.member.findMany({
include: {
data: true,
},
});
return await prisma.member.findMany({
include: {
data: true,
},
});
Leonidas
Leonidas3y ago
Have you migrated ur database and generated a new prisma client after adding the memberData relation?
Liam
LiamOP3y ago
Yes, did some further research and found that Prisma actually does not generate types for the relationship, so I winded up using type MemberWithData = Prisma.MemberGetPayload<{ include: { data: true } }>; and then cast the results as this type. Not my favorite solution but it is working. https://github.com/prisma/prisma/discussions/10928
GitHub
Generated prisma types are missing relationships in their exported ...
Bug description So I am really not sure if this is a bug, my mistake or some really stupid feature. I started using prisma in force a few days ago and so far, I love it, but I am struggling to unde...
Leonidas
Leonidas3y ago
Really weird. I query related rows all across my app and never had that problem Are you using a noSQL database?
Want results from more Discord servers?
Add your server