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?
![No description](https://cdn.answeroverflow.com/1230849893560746037/image.png)
![No description](https://cdn.answeroverflow.com/1230849893841768518/image.png)
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 👍