Skip to content

[ORM] CreateRelationField typing is missing when creating a delegated Model from a polymorphic Model #2753

Description

@iPommes

Description and expected behavior
When wanting to create a new model with the create or createMany methods on a submodel of a delegated model (so Main has the @@delegate and Sub is a delegate of Main and you want to create a Sub entity) and this sub model has a relation the usual CreateRelationField typing is missing on all relation fields and only will be undefined.

Environment (please complete the following information):

  • ZenStack version: 3.8.3
  • Database type: PostgreSQL
  • Node.js/Bun version: 1.3.14
  • Package manager: Bun

Example schema

model Main with Base {
  item   Item   @relation(fields: [itemId], references: [id], onDelete: Cascade)
  itemId String

  @@unique([permissionId, itemId])
  @@delegate(type)
}

model Sub extends Main {
  group   Group  @relation(fields: [groupId], references: [id], onDelete: Cascade)
  groupId String
}

and then creating a Sub via zenstack.sub.create:

      await db.sub.create({
        data: {
          item: // <-- this is undefined and untyped
          group: // <-- aswell as relation lying directly on the Sub
        },
      })

usually there will be functions like connect, create, ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions