I am trying to create a one-to-many relationship between a user and posts. I can create the database schema and can write / query all ok but it appears the prisma client that is being generated doesn't have the relationships on the type.
For example, my schema looks like this:
model User {
id Int @id @default(autoincrement())
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
author User @relation(fields: [authorId], references: [id])
authorId Int
}
I then run npx prisma generate
which creates a client with the following types
/**
* Model User
*
*/
export type User = {
id: number
}
/**
* Model Post
*
*/
export type Post = {
id: number
authorId: number
}
I would expect the user type to look like this:
export type User = {
id: number;
posts: Post[];
}
Have I defined my Prisma schema correctly? What do I need to do to get the type to include the relation?
ctx.prisma.menu.findFirst
method has a return type of(User & { posts: Post[]; })
Is the only way to combine the types manually?