Bird
0
0

Identify the mistake in this NestJS entity relation:

medium📝 Debug Q6 of 15
NestJS - Database with TypeORM
Identify the mistake in this NestJS entity relation:
class Article {
  @OneToMany(() => Comment)
  comments: Comment;
}
AThe property 'comments' should be an array, not a single Comment
BThe decorator should be @ManyToOne instead of @OneToMany
CThe relation callback function is missing the inverse side
DThe entity class name 'Article' is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check property type

    @OneToMany defines a one-to-many relation, so the property must be an array.
  2. Step 2: Identify error

    The property comments is declared as a single Comment, which is incorrect.
  3. Final Answer:

    The property 'comments' should be an array, not a single Comment -> Option A
  4. Quick Check:

    @OneToMany requires array property [OK]
Quick Trick: @OneToMany properties must be arrays [OK]
Common Mistakes:
  • Declaring property as single entity instead of array
  • Omitting inverse side in relation callback
  • Confusing @OneToMany with @ManyToOne

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes