Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#2,638 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
15/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
typescript
Ambito
database

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
2.9k
Fork
157
Merge medio
11h 42m
PR unite (30g)
20

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di zenstackhq/zenstack

Tutte le issue di zenstackhq/zenstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.