Skip to content

Zenstack does not let me define multiple fields that are referencing the same model #653

Description

@cankush625

Description and expected behavior
I have a blog model that extends the AuditModel. Each blog has an author and the audit model has two fields which are created_by and updated_by. All these three fields reference to the User table, which is obvious that all three actors are users. When I try to generate a .prisma file using npx zenstack generate command, it gives a validation error that these fields refer to the same relation to model "User".

Model's in .zmodel file:

abstract model AuditModel {
    createdBy User @relation(fields: [createdById], references: [id])
    updatedBy User @relation(fields: [updatedById], references: [id])
    createdById Int
    updatedById Int
}

model Blog extends AuditModel {
  author User @relation(fields: [authorId], references: [id])
  authorId Int
  title String
  content String

  @@unique([authorId, title])
  @@index([id, authorId])
}

Expected result:
Multiple fields should be allowed to refer to the same model

Screenshots
image

Environment:

  • ZenStack version: 1.0.0-beta.20
  • Prisma version: 5.1.1
  • Database type: Postgresql

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions