The example in the documentation looks like this:
const getUser = await prisma.user.findUnique({
where: {
id: 1,
},
include: {
posts: {
select: {
title: true,
},
},
},
})
But when I want to read the property getUser.posts
I get the following error:
TS2339: Property 'posts' does not exist on type 'User'.
Where can I find the correct type definitions the for the includes option?
The generated types do not include relations because queries don't return relations by default. To include the related models in your type, use the provided Prisma utility types like so:
import { Prisma } from '@prisma/client'
type UserWithPosts = Prisma.UserGetPayload<{
include: { posts: true }
}>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With