Improve relation syntax for simple scenarios
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 47.6k
- Forks
- 2.5k
- Avg merge
- 21h 59m
- Merged PRs (30d)
- 95
Description
Problem
Right now, defining a relation in the Prisma schema is quite verbose due to the required relation scalar field:
model User {
id Int @id @default(autoincrement())
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
author User @relation(fields: [authorId], references: [id])
authorId Int // relation scalar field
}
In implicit m-n-relations, we also need to use the (You don't need them now)@relation attribute:
model Post {
id Int @id @default(autoincrement())
categories Category[] @relation(references: [id])
}
model Category {
id Int @id @default(autoincrement())
posts Post[] @relation(references: [id])
}
Solution
Maybe we can figure out a way how Prisma can infer the information that's currently made explicit in the schema. Another solution could be to add a feature to the Prisma schema formatter which can insert the required fields automatically.
Contributor guide
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.
Research direction
Start by reviewing the Prisma schema relation examples and the discussion around relation scalar fields. The issue presents two possible directions—inference or formatter support—without selecting one. Done would require an agreed approach that makes simple relations less verbose while preserving correct relation information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100