zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

The generated prisma failed to compile if both the relation field of entity and it's base type exsit in one model #1100

Closed jiashengguo closed 7 months ago

jiashengguo commented 7 months ago

The below schema passes the ZenStack CLI, but the generated Prisma schema fails validation:

Error: Prisma schema validation - (get-dmmf wasm)
Error code: P1012
error: Error validating field `posts` in model `User`: The relation field `posts` on model `User` is missing an opposite relation field on the model `Post`. Either run `prisma format` or add it manually.
model User {
  id String @id @default(cuid())
  name String?
  content Content[]
  post Post[]
}
model Content {
  id String @id @default(cuid())
  published Boolean @default(false)
  contentType String
  @@delegate(contentType)

  user User @relation(fields: [userId], references: [id])
  userId String
}

model Post extends Content {
  title String
}
model Image extends Content {
  url String
}
ymc9 commented 7 months ago

Fixed in 2.0.0-alpha.6