zod-prisma-types
zod-prisma-types copied to clipboard
Cant omit on 'withRelationsSchema'
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?
Would love to know how to omit relation fields as well =/
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.
To conclude: for normal types this can be implemented but for recursive types the .pick, .omit, etc. methods will never be possible 😞
the explanation for why is in this comment https://github.com/chrishoermann/zod-prisma-types/issues/102#issuecomment-1466197672