Skip to content

delegate aux fields appearing in WhereUniqueInput schema, when aux field is not first in a @@unique constraint #2028

@diesal11

Description

@diesal11

Description and expected behavior
Given the following schema:

enum FooType {
    Bar
    Baz
}

model User {
    id          String       @id @default(cuid())
    userFolders UserFolder[]
}

model Foo {
    id          String       @id @default(cuid())
    type        FooType

    userFolders UserFolder[]

    @@delegate(type)
}

model Bar extends Foo {
    name String
}

model Baz extends Foo {
    age Int
}

model UserFolder {
    id     String @id @default(cuid())
    userId String
    fooId  String
    path   String

    user   User   @relation(fields: [userId], references: [id])
    foo    Foo    @relation(fields: [fooId], references: [id])

    @@unique([userId, fooId])
}

An invalid Zod schema is generated for UserFolderWhereUniqueInputObjectSchema

This schema attempts to import CompoundUniqueInput schemas for userId_delegate_aux_UserFolder_fooId_Bar/Baz, but these are removed during schema generation, causing a runtime error when these schemas are used.

Screenshots

Image

Environment (please complete the following information):

  • ZenStack version: 12.2.1
  • Prisma version: 6.4.1
  • Database type: Postgresql

Additional context

The bug seems to be within the zod schema generator, where .startsWith(DELEGATE_AUX_RELATION_PREFIX) is still used instead of .includes(DELEGATE_AUX_RELATION_PREFIX) to filter delegate fields on an object. The CompoundUniqueInput schemas are filtered out correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions