Recall & Review
beginner
What is a relation in Prisma?
A relation in Prisma connects two models, like a link between tables in a database. It helps you organize and access related data easily.
Click to reveal answer
intermediate
How do you define a one-to-many relation in Prisma schema?
You add a field with type of the related model and use @relation attribute. For example, a User has many Posts: <br>
model User {<br> id Int @id @default(autoincrement())<br> posts Post[]<br>}<br>model Post {<br> id Int @id @default(autoincrement())<br> userId Int<br> user User @relation(fields: [userId], references: [id])<br>}Click to reveal answer
beginner
What does the @relation attribute do in Prisma?
The @relation attribute tells Prisma how two models are connected. It specifies which fields link the models and which fields are referenced, making the relation clear.
Click to reveal answer
intermediate
How do you represent a many-to-many relation in Prisma?
You create two models with array fields of each other. Prisma automatically creates a join table. Example:<br>
model Student {<br> id Int @id @default(autoincrement())<br> courses Course[]<br>}<br>model Course {<br> id Int @id @default(autoincrement())<br> students Student[]<br>}Click to reveal answer
beginner
Why are relations important in Prisma when using NestJS?
Relations help NestJS apps fetch and manage connected data easily. They let you get related records in one query, making your app faster and simpler to write.Click to reveal answer
In Prisma, how do you link a Post to a User in a one-to-many relation?
✗ Incorrect
You add a userId field in Post and use @relation to connect it to User.
What does Prisma create automatically for many-to-many relations?
✗ Incorrect
Prisma creates a join table behind the scenes to manage many-to-many relations.
Which Prisma attribute specifies how two models are connected?
✗ Incorrect
The @relation attribute defines the connection between models.
In a one-to-many relation, which side holds the foreign key field?
✗ Incorrect
The many side holds the foreign key field to link back to the one side.
Why use relations in Prisma with NestJS?
✗ Incorrect
Relations let you fetch connected data easily and keep your code simple.
Explain how to set up a one-to-many relation between User and Post models in Prisma.
Think about which model holds the foreign key and how @relation connects them.
You got /4 concepts.
Describe the difference between one-to-many and many-to-many relations in Prisma.
Consider how data is connected and stored in the database.
You got /4 concepts.