Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
diesal11 opened this issue Mar 6, 2025 · 0 comments · Fixed by #2029

Comments

@diesal11
Copy link
Contributor

diesal11 commented Mar 6, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant