chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
579 stars 43 forks source link

ModelWithOptionalRelations #105

Closed mbsanchez closed 1 year ago

mbsanchez commented 1 year ago

I know we can generate types like ModelWithRelations ModelOptionalDefaultWithRelations ModelPartialWithRelations

I have a use case where I need to return the model with its relations but not all of them, it is possible to generate types like: ModelWithPartialRelations ModelOptionalDefaultWithPartialRelations ModelPartialWithPartialRelations

I know there is a type ModelPartialRelations so, it could be created as

export type ModelWithPartialRelations = z.infer<typeof ModelSchema> & ModelPartialRelation; export type ModelOptionalDefaultWithPartialRelations = z.infer<typeof ModelOptionalDefaultsSchema> & ModelPartialRelation; export type ModelPartialWithPartialRelations = z.infer<typeof ModelPartialSchema> & ModelPartialRelation;

thank you!

chrishoermann commented 1 year ago

@mbsanchez Thanks for the request. That would definitly be a useful addition. I'll see to it and report back.

chrishoermann commented 1 year ago

@mbsanchez I implemented generation of the following schemas in the latest version:

ModelWithPartialRelations ModelOptionalDefaultsWithPartialRelations

the last suggested schema ModelPartialWithPartialRelations has already been implemented as ModelPartialWithRelations. in this schema all fields should be optional.