Skip to content

Generate throws when combining polymorphism and self-relations #1764

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
platon-ivanov opened this issue Oct 8, 2024 · 1 comment
Closed
Milestone

Comments

@platon-ivanov
Copy link

Description and expected behavior

Using the example from Prisma docs. https://www.prisma.io/docs/orm/prisma-schema/data-model/relations/self-relations and add adding polymorphism like this:

model User {
  id          Int     @id @default(autoincrement())
  name        String?
  successorId Int?    @unique
  successor   User?   @relation("BlogOwnerHistory", fields: [successorId], references: [id])
  predecessor User?   @relation("BlogOwnerHistory")

  userType String
  @@delegate(userType)
}

model Organization extends User {
}

model Person extends User {
}

Throws the error:

$ npx zenstack generate

⌛️ ZenStack CLI v2.4.1, running plugins
✔ Generating Prisma schema
Prisma schema loaded from db/logical-1724338739613.prisma
Error: Prisma schema validation - (get-dmmf wasm)
Error code: P1012
error: Error validating model "User": Wrongly named relation detected. The fields `delegate_aux_User_successor_Organizati_0` and `delegate_aux_User_predecessor_Organiza_0` in model `User` both use the same relation name. Please provide different relation names for them through `@relation(<name>).
  -->  db/logical-1724338739613.prisma:25
   |
24 |     userType String
25 |     delegate_aux_User_successor_Organizati_0 Organization? @relation("BlogOwnerHistory", fields: [delegate_aux_User_successorId_Organiza_0], references: [id], map: "delegate_aux_User_successor_Organizati_0_fk")
26 |     delegate_aux_User_successorId_Organiza_0 Int? @unique(map: "delegate_aux_User_successorId_Organiza_1")
   |

Validation Error Count: 1
[Context: getDmmf]

Prisma CLI Version : 5.14.0
✖ Generating PrismaClient enhancer
Prisma Enhancer: Failed to run "prisma generate"

This example was taken from the according Discord discussion. In my use, the same error is thrown with one-to-many and many-to-many relations.

Environment (please complete the following information):

  • ZenStack version: 2.6.2
  • Prisma version: 5.20.0
  • Database type: Postgresql
@ymc9 ymc9 added this to the v2.8.0 milestone Oct 21, 2024
ymc9 added a commit that referenced this issue Oct 31, 2024
@ymc9
Copy link
Member

ymc9 commented Nov 6, 2024

Fixed in 2.8.0

@ymc9 ymc9 closed this as completed Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants