Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#2,753 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript
Domain
database

Research direction

Reproduce with the example schema: Main carrying @@delegate(type) and Sub extends Main, then inspect the generated typing for zenstack.sub.create and check where CreateRelationField should be applied to the inherited item and the Sub-only group. The generator that expands delegate/polymorphic models and their relations produces these types; compare what it emits for Sub against a non-delegated model with the same relations. Done means db.sub.create({ data: { item, group } }) exposes the usual connect/create relation fields with correct types. The payload names no file, so locating the type-generation code is part of the work.

Written by the indexing model from the issue text.

Description

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, ...

Dominant language
TypeScript
Stars
2.9k
Forks
157
Avg merge
11h 42m
Merged PRs (30d)
20

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from zenstackhq/zenstack

All issues in zenstackhq/zenstack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.