0
0
NestJSframework~5 mins

Relations (OneToMany, ManyToOne, ManyToMany) in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does a OneToMany relation represent in NestJS with TypeORM?
It means one entity instance can be linked to many instances of another entity. For example, one author can have many books.
Click to reveal answer
beginner
Explain the ManyToOne relation in NestJS.
Many instances of an entity relate to one instance of another entity. For example, many books belong to one author.
Click to reveal answer
intermediate
How does a ManyToMany relation work in NestJS?
It connects many instances of one entity to many instances of another. For example, many students can enroll in many courses.
Click to reveal answer
intermediate
In NestJS, which decorator is used to define the owner side of a ManyToOne relation?
The @ManyToOne decorator is used on the owner side, which holds the foreign key to the related entity.
Click to reveal answer
intermediate
What is the purpose of the @JoinTable() decorator in a ManyToMany relation?
It marks the owner side of the ManyToMany relation and creates a join table to store the relation links.
Click to reveal answer
Which decorator defines a one-to-many relation in NestJS with TypeORM?
A@OneToMany
B@ManyToOne
C@ManyToMany
D@JoinColumn
In a ManyToOne relation, where is the foreign key stored?
AOn the entity with the ManyToOne decorator
BOn the entity with the OneToMany decorator
CIn a separate join table
DNo foreign key is used
What does the @JoinTable() decorator do in a ManyToMany relation?
ADefines a foreign key column
BCreates a join table to link both entities
CMarks a column as primary key
DSpecifies eager loading
Which relation type allows many instances of one entity to relate to many instances of another?
AManyToOne
BOneToMany
CManyToMany
DOneToOne
If an Author has many Books, which decorator would you use on the Author entity?
A@ManyToMany
B@ManyToOne
C@JoinColumn
D@OneToMany
Describe how to set up a OneToMany and ManyToOne relation between two entities in NestJS.
Think about how one author can have many books and how each book belongs to one author.
You got /4 concepts.
    Explain the role of @JoinTable in a ManyToMany relation and which side should have it.
    Imagine a table that connects students and courses they attend.
    You got /4 concepts.