[ORM] CreateRelationField typing is missing when creating a delegated Model from a polymorphic Model
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from zenstackhq/zenstack
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
zenstackhq/zenstack#2873 ·
Maintainers usually reply within 1 day
-
runtime
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zenstackhq/zenstack#2868 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
zenstackhq/zenstack#2694 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
zenstackhq/zenstack#2659 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
zenstackhq/zenstack#2542 · 1 comment ·
Maintainers usually reply within 1 day
All issues in zenstackhq/zenstack
Similar issues
-
A hung CI job runs for 6 hours before it is cancelledPossibly taken @Olanetsoft claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Olanetsoft/agent-lookout#110 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
thedotmack/claude-mem#4757 ·
Maintainers usually reply within 1 day
-
🐛 bug 🗺️ MCP OAuth
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
LibreChat-AI/LibreChat#17077 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100