The Three Shapes
Every relation in a relational database is one of three shapes:
- One-to-one — a user has one profile
- One-to-many — a user has many posts
- Many-to-many — a post has many tags and a tag has many posts
Prisma has idiomatic syntax for all three. Once you see them side by side, the pattern clicks.
One-to-Many (the most common)
A User has many Post rows. The foreign key lives on the Post side.
model User {
id Int @id @default(autoincrement())
email String @unique
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
authorId Int
author User @relation(fields: [authorId], references: [id])
}The posts field on User is virtual — Prisma uses it for queries like include: { posts: true } but there's no column for it. The real data is the authorId column on Post.
One-to-One
A User has one Profile