Infer typescript type from table with relations
I have a pg table with a one to many relationship. I would like to get the typescript type of this table including the one to many relation.
I've attached images of my schema files. Currently, I have come up with a solution which seems to work but seems a 'bit scuffed' as I can see it being prone to needing ammendment if I change relations in the future.
This is the type I have currently come up with.
Is there some other 'infer......` type that I can use that will achieve what I need?
3 Replies
GitHub
Implement infering table model with relations · Issue #695 · drizzl...
Prisma API: import { Prisma } from '@prisma/client' // 1: Define a type that includes the relation to
Post
const userWithPosts = Prisma.validator<Prisma.UserDefaultArgs>()({ include...This also allows you to specify columns on the parent table
Thank you buddy! This seems to be exactly what I was looking for. Appreciate it 👍