Bird
0
0

In NestJS using TypeORM, which decorator correctly defines a OneToMany relationship from an Author entity to a Book entity?

easy📝 Conceptual Q11 of 15
NestJS - Database with TypeORM
In NestJS using TypeORM, which decorator correctly defines a OneToMany relationship from an Author entity to a Book entity?
A@OneToMany(() => Book, book => book.author)
B@ManyToOne(() => Book, book => book.author)
C@ManyToMany(() => Book, book => book.author)
D@OneToOne(() => Book, book => book.author)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the relationship direction

    A OneToMany relationship means one Author has many Books.
  2. Step 2: Identify the correct decorator syntax

    The decorator @OneToMany(() => Book, book => book.author) correctly sets this relation from Author to Book.
  3. Final Answer:

    @OneToMany(() => Book, book => book.author) -> Option A
  4. Quick Check:

    OneToMany from Author to Book = @OneToMany [OK]
Quick Trick: OneToMany decorator links one entity to many others [OK]
Common Mistakes:
  • Confusing OneToMany with ManyToOne
  • Using ManyToMany instead of OneToMany
  • Incorrect arrow function syntax in decorator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes