Relations
- Relations
A relation is a connection between two models in the Prisma schema.
Types of relations
There are three different types of relations in Prisma
- One-to-One (also called 1–1-relation)
- One-to-Many (also called 1-n-relation)
- Many-to-Many (also called m-n-relation)
The following Prisma schema includes every type of relation:
- 1–1:
User↔Profile - 1-n:
User↔Post - m-n:
Post↔Category

One-to-one relations
One-to-one (1–1) relations refer to relations where at most one record can be connected on both sides of the relation. In the example below, there is a one-to-one relation between User and Profile:

The userId relation scalar is a direct representation of the foreign key in the underlying database. This one-to-one relation expresses the following:
- “a user can have zero or one profile” (because the
profilefield is optional onUser) - “a profile must always be connected to one user”
Multi-field relations in relational database
In relational databases only, you can also define use multi-field IDs to define a 1–1 relation:

Required and optional 1–1 relation fields
In a one-to-one relation, the side of the relation without a relation scalar (the field representing the foreign key in the database) must be optional:

Choosing which side should store the foreign key in a 1–1 relation
In 1–1 relations, you can decide yourself which side of the relation you want to annotate with the @relation attribute (and therefore holds the foreign key).
In the following example, the relation field on the Profile model is annotated with the @relation attribute. userId