- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 126
Description
Description and expected behavior
I've been playing around with the 2.0 polymorphic features of zenstack and ran into an issue I can't seem to get around / find documented here:
"Generating Prisma schema" completes successfully but I run into the following error during "Generating PrismaClient enhancer"
error: Error parsing attribute "@relation": The given constraint name `UserFavorite_id_fkey` has to be unique in the following namespace: on model `UserFavorite` for primary key, indexes, unique constraints and foreign keys. Please provide a different name using the `map` argument.
  -->  schema.prisma:69
   | 
68 |     delegate_aux_personId String
69 |     delegate_aux_studio Studio @relation(fields: [id], references: [id])
70 |     delegate_aux_studioId String
   | 
Validation Error Count: 4
[Context: getDmmf]
Prisma CLI Version : 5.10.2
✖ Generating PrismaClient enhancer
Prisma: Failed to run "prisma generate
Here is a simplified version of my schema.zmodel:
generator client {
  provider = "prisma-client-js"
}
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
model User {
    id            String    @id @default(cuid())
    name          String
    userRankings UserRanking[]
    userFavorites UserFavorite[]
}
model Entity {
  id      String          @id @default(cuid()) 
  name    String  
  type String
  userRankings UserRanking[]
  userFavorites UserFavorite[]
  @@delegate(type)
}
model Person extends Entity {
}
model Studio extends Entity {
}
model UserRanking {
  id      String       @id @default(cuid()) 
  rank     Int
  entityId      String
  entity        Entity        @relation(fields: [entityId], references: [id], onUpdate: NoAction)
  userId   String
  user     User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: NoAction)
}
model UserFavorite {
  id      String       @id @default(cuid()) 
  entityId      String
  entity        Entity        @relation(fields: [entityId], references: [id], onUpdate: NoAction)
  userId   String
  user     User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: NoAction)
}
Based on the error message, I think a possible solution would be to add a map property to the relation attribute as it suggests. When I go in and modify node_modules\.zenstack\delegate.prisma just to try it out, the IDE error goes away at least so I think its promising. Maybe on generation this should be added? Or an option to specify this somewhere in the zmodel?
// delegate.prisma
-- delegate_aux_studio Studio @relation(fields: [id], references: [id])
++ delegate_aux_studio Studio @relation(fields: [id], references: [id], map: "studio")
Environment (please complete the following information):
- ZenStack version: 2.0.0-alpha.1
- Prisma version: 5.10.2
- Database type: postgresql
Additional context
Oddly enough changing the generator provider to sqlite seems to remedy the issue (something prisma related?) but I was hoping to use postgresql
Thanks
-Andrew