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

[Feature Request] a foreign constraint attribute for scalar fields not implying a relation mapping

Open
#2,638 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
15/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript
Domain
database

Research direction

Language-design request for the ZModel schema DSL: a new @foreign attribute must be threaded from attribute declaration through schema validation to generated migration DDL. No file or test is named, so start where built-in attributes like @relation are declared, parsed and validated, then follow migration generation. Open semantic question: SQL foreign keys require a unique referenced column, so references: [kind] needs a design decision; done means the schema compiles and the migration emits the constraint.

Written by the indexing model from the issue text.

Description

Problem

model ModelA {
 id Int,
 name String
 bKind String        //should matches a value that exists in ModelB.kind
}

model ModelB {
 id Int,
 name String
 kind String  //this is not unique and can't identify a single ModelB row
}

Unfortunately, AFAIK the only current way of describing a FK is through a @relation attribute that enforce matching an unique and effective object, that should be present in the linked model.
That's not ideal when one just want to ensure scalars consistency from the described zmodel.

Proposal
A new @foreign attribute allowing to describe a simple FK constraint would be nice
i.e:

model TableA {
 id Int,
 name String
 bKind String       @foreign(fields:[bKind], references:[kind], from: ModelB)
}

Describe alternatives you've considered
Adding custom SQL to create the FK in a migration. But, IMHO, the ORM model should allow describing simple FK and abstract their creation.

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.