chrishoermann / zod-prisma-types

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

Prisma does not include the id fields for a relationship #242

Closed Darkbound closed 4 months ago

Darkbound commented 4 months ago

Describe the bug A clear and concise description of what the bug is.

I have this model:

model Client {
  id             String       @id @default(cuid())
  createdAt      DateTime     @default(now()) @map("created_at")
  updatedAt      DateTime     @updatedAt @map("updated_at")
  name           String
  email          String?      @unique
  phone          String?
  firstName      String?      @map("first_name")
  lastName       String?      @map("last_name")
  currency       Currency     @default(USD)
  organizationId String       @map("organization_id")
  organization   Organization @relation(fields: [organizationId], references: [id])
  projects       Project[]
}

The generated create input schema looks like this:

export const ClientCreateInputSchema: z.ZodType<Prisma.ClientCreateInput> = z.object({
  id: z.string().cuid().optional(),
  createdAt: z.coerce.date().optional(),
  updatedAt: z.coerce.date().optional(),
  name: z.string(),
  email: z.string().optional().nullable(),
  phone: z.string().optional().nullable(),
  firstName: z.string().optional().nullable(),
  lastName: z.string().optional().nullable(),
  currency: z.lazy(() => CurrencySchema).optional(),
  organization: z.lazy(() => OrganizationCreateNestedOneWithoutClientsInputSchema),
  projects: z.lazy(() => ProjectCreateNestedManyWithoutClientInputSchema).optional()
}).strict();

It must have organizationId instead of organization

The create many input schema has it:

export const ClientCreateManyInputSchema: z.ZodType<Prisma.ClientCreateManyInput> = z.object({
  id: z.string().cuid().optional(),
  createdAt: z.coerce.date().optional(),
  updatedAt: z.coerce.date().optional(),
  name: z.string(),
  email: z.string().optional().nullable(),
  phone: z.string().optional().nullable(),
  firstName: z.string().optional().nullable(),
  lastName: z.string().optional().nullable(),
  currency: z.lazy(() => CurrencySchema).optional(),
  organizationId: z.string()
}).strict();

Package versions (please complete the following information):