Bird
0
0

Which of the following is the correct syntax to define a ManyToMany relation between User and Role entities in NestJS TypeORM?

easy📝 Syntax Q3 of 15
NestJS - Database with TypeORM
Which of the following is the correct syntax to define a ManyToMany relation between User and Role entities in NestJS TypeORM?
A@OneToMany(() => Role) roles: Role[];
B@ManyToMany(() => Role) roles: Role[];
C@ManyToOne(() => Role) roles: Role[];
D@OneToOne(() => Role) roles: Role[];
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct decorator for ManyToMany

    The @ManyToMany decorator is used to define many-to-many relations between entities.
  2. Step 2: Check syntax correctness

    @ManyToMany(() => Role) roles: Role[]; correctly uses @ManyToMany(() => Role) and defines roles as an array, which is the correct syntax.
  3. Final Answer:

    @ManyToMany(() => Role) roles: Role[]; -> Option B
  4. Quick Check:

    ManyToMany syntax uses array and decorator [OK]
Quick Trick: ManyToMany relations always use arrays on both sides [OK]
Common Mistakes:
  • Using OneToMany or ManyToOne for many-to-many
  • Not using array type for related entities
  • Missing the arrow function in decorator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes