How to create Prisma Client's generated types with nested models?
Hi guys,
I am currently trying to define generate model types using Prisma.validator to include relations.
I've followed this documentation: https://www.prisma.io/docs/orm/prisma-client/type-safety/operating-against-partial-structures-of-model-types#problem-using-variations-of-the-generated-model-type
However, I am confused how I can set up with model with nested models.
For example, I have a Post that has UserSocial Model. In addition, UserSocial has 1 to 1 relationship with User model.
I want to generate a PostWithUserSocial but also has the nested User model included.
Does anyone know how I can achieve this?
Operating against partial structures of your model types | Prisma D...
This page documents various scenarios for using the generated types from the Prisma namespace
2 Replies
Hey @fivewen 👋
Assuming your models looks like this:
You can do something like this to generate the nested type:
Worked like a charm. That's intuitive, thanks!
One more question, how should I nest when it has a self-relationship?
For example, I want to implement a comment type where comment has replies mapped which is a list of comments.
So far, this is what I have: