Closed BitPhoenix closed 2 years ago
Added pull request with proposed fix: https://github.com/omar-dulaimi/prisma-zod-generator/pull/38
Note: updated fix implementation slightly from original comment above
Hey @BitPhoenix Thank you for your continued work on this and the other project. I'll be taking a look at your PR now.
Bug description
Tagging @Shahidul1004 in this one as you might have some good insights here as well
I noticed that {Model}Include.schema.ts is generated for models that do not have a relation to any another model and the result looks something like this:
const Schema: z.ZodType<Prisma.{Model}Include> = z.object({}).strict();
There is an error line under
Prisma.{Model}Include
because it looks like Prisma only generates a {Model}Include type if the model contains a relation to another model. So the generated {Model}Include.schema.ts is referencing a Prisma type that does not exist đŸ˜As a fix, I believe this section in
include-helpers
needs to be wrapped in an if condition checking forhasRelation
, wherehasRelation
is set to true if we encounterisRelationField === true
@Shahidul1004 Curious if you're able to reproduce this and see if the fix works đŸ¤”
How to reproduce
Run
npm run generate-example
with a schema.prisma containing a model with no relation to another model, and look at the generated {Model}Include.schema.ts file that is generated.Expected behavior
Expected behavior: {Model}Include.schema.ts is not generated for models that don't have relations with any other models.
Prisma information
The schema.prisma in this repo, just including a model that does not have a relation with any other model.
Environment & setup
Mac OS + included schema.prisma if you add a model that does not have a relation with any other model
Prisma Version
N / A