Skip to content

Polymorphic object does not work with Mixin abstract model #2351

@mjperlini

Description

@mjperlini

Trying to use a polymorphic model with a base object that includes an abstract model.

type BaseEntity {
  id         String   @id @default(ulid())
  createdOn  DateTime @default(now())
  updatedOn  DateTime @updatedAt
  isDeleted  Boolean  @default(false)
  isArchived Boolean  @default(false)
}

model RoutineData with BaseEntity {
  dataType  DataType
  sortOrder Float?
  title     String?

  routineId String
  Routine   Routine  @relation(fields: [routineId], references: [id])

  @@delegate(dataType)
  @@allow('all', auth().id == Routine.userId)
}

model DataText extends RoutineData {
  text String
}

Reading DataText object fails with 'dataText.createdOn' does not exist. This pattern worked with V2.

I was able to make it work by copying the BaseEntity rows into the RoutineData table directly.

model RoutineData {
  id         String   @id @default(ulid())
  createdOn  DateTime @default(now())
  updatedOn  DateTime @updatedAt
  isDeleted  Boolean  @default(false)
  isArchived Boolean  @default(false)

  dataType  DataType
  sortOrder Float?
  title     String?

  routineId String
  Routine   Routine  @relation(fields: [routineId], references: [id])

  @@delegate(dataType)
  @@allow('all', auth().id == Routine.userId)
}

model DataText extends RoutineData {
  text String
}

Metadata

Metadata

Assignees

No one assigned

    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