Bird
0
0

You want to model a blog where each Author can write many Posts, and each Post can have many Tags. Which combination of relations correctly models this in NestJS TypeORM?

hard📝 Application Q8 of 15
NestJS - Database with TypeORM
You want to model a blog where each Author can write many Posts, and each Post can have many Tags. Which combination of relations correctly models this in NestJS TypeORM?
AAuthor has @ManyToMany Posts; Post has @ManyToMany Author; Post has @OneToOne Tags; Tag has @OneToOne Posts
BAuthor has @ManyToOne Posts; Post has @OneToMany Author; Post has @OneToMany Tags; Tag has @ManyToOne Posts
CAuthor has @OneToMany Posts; Post has @ManyToOne Author; Post has @ManyToMany Tags; Tag has @ManyToMany Posts
DAuthor has @OneToOne Posts; Post has @OneToOne Author; Post has @ManyToOne Tags; Tag has @OneToMany Posts
Step-by-Step Solution
Solution:
  1. Step 1: Model Author to Posts relation

    Each Author writes many Posts, so Author uses @OneToMany and Post uses @ManyToOne.
  2. Step 2: Model Post to Tags relation

    Posts can have many Tags and Tags can belong to many Posts, so both use @ManyToMany.
  3. Final Answer:

    Author has @OneToMany Posts; Post has @ManyToOne Author; Post has @ManyToMany Tags; Tag has @ManyToMany Posts -> Option C
  4. Quick Check:

    OneToMany + ManyToOne and ManyToMany pairs [OK]
Quick Trick: OneToMany pairs with ManyToOne; ManyToMany pairs with ManyToMany [OK]
Common Mistakes:
  • Mixing OneToMany with ManyToMany incorrectly
  • Using OneToOne where many relations exist
  • Confusing owning and inverse sides

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes