chrishoermann / zod-prisma-types

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

Cant omit on 'withRelationsSchema' #168

Open gregg-cbs opened 11 months ago

gregg-cbs commented 11 months ago

I cant omit fields on WithRelationsSchemas because they are z.ZodType .

export const ProductWithRelationsSchema: z.ZodType<ProductWithRelations> = ProductSchema.merge(z.object({
  suppliers: z.lazy(() => SupplierPSchema).array(),
  pricing: z.lazy(() => PricingPSchema),
}))

Ideally I would like to create an Input by doing this:

const ProductInputSchema = ProductWithRelationsSchema.omit({
  id: true, slug: true, permalink: true
})

I enabled and tried createInputTypes = true but that doesnt give the models/schemas that I want. Do you have a suggestion for this?

renatoaraujoc commented 11 months ago

Would love to know how to omit relation fields as well =/

gregg-cbs commented 11 months ago

I have now decided to use this generator to create schemas which I then copy into my own folder of files and modify and then I import my schema and types from there - i exclude the generated folder from git.

This seems to be the only way to achieve this. The generator is still useful in that it does the bulk of the work. The downside to my approach is that you have to manually update your schemas when your prisma schema changes - which isnt the end of the world.