chrishoermann/zod-prisma-types

Prisma does not include the id fields for a relationship

Closed this issue · 0 comments

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):

  • zod: 3.21.1
  • prisma: 5.5.2