Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#2,638 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
15/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
typescript
Lĩnh vực
database

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
2.9k
Fork
157
Merge trung bình
11 giờ 42 phút
Pull request đã merge (30 ngày)
20

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của zenstackhq/zenstack

Tất cả issue của zenstackhq/zenstack

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.