Bird
0
0

You have entities User, Group, and Permission. Users belong to many Groups, and Groups have many Permissions. How do you define these relations in NestJS TypeORM?

hard📝 Application Q9 of 15
NestJS - Database with TypeORM
You have entities User, Group, and Permission. Users belong to many Groups, and Groups have many Permissions. How do you define these relations in NestJS TypeORM?
AUser and Group: @OneToMany; Group and Permission: @ManyToOne
BUser and Group: @ManyToOne; Group and Permission: @OneToMany
CUser and Group: @ManyToMany; Group and Permission: @ManyToMany
DUser and Group: @OneToOne; Group and Permission: @OneToOne
Step-by-Step Solution
Solution:
  1. Step 1: Analyze User to Group relation

    Users belong to many Groups and Groups have many Users, so this is a many-to-many relation.
  2. Step 2: Analyze Group to Permission relation

    Groups have many Permissions and Permissions can belong to many Groups, so this is also many-to-many.
  3. Final Answer:

    User and Group: @ManyToMany; Group and Permission: @ManyToMany -> Option C
  4. Quick Check:

    ManyToMany for both relations [OK]
Quick Trick: Many-to-many when both sides have multiple related entities [OK]
Common Mistakes:
  • Using OneToMany or ManyToOne for many-to-many relations
  • Assuming OneToOne for group memberships
  • Not defining inverse sides

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes