In the previous step, we added attributes (columns) to all our entities (tables).
Now weβll connect them together using relationships.
π A relationship shows how two entities are linked to each other.
For example:
In Prisma (or any relational database), we connect tables using Foreign Keys (FKs) and the @relation() field.
One user can have only one profile.
One profile belongs to one user.
So this is a One-to-One relationship.
model User {
id String @id @default(uuid())
username String @unique
password String
email String @unique
isVerified Boolean @default(false)
profile Profile? @relation("UserProfile")
tweets Tweet[]
notifications Notifications[]
messagesSent Messages[] @relation("SentMessages")
messagesReceived Messages[] @relation("ReceivedMessages")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Profile {
id String @id @default(uuid())
bio String?
profileCategory ProfileCategory
userId String @unique
user User @relation("UserProfile", fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}