Bird
0
0

What is incorrect about this NestJS TypeORM relation?

medium📝 Debug Q7 of 15
NestJS - Database with TypeORM
What is incorrect about this NestJS TypeORM relation?
class Review {
  @ManyToOne(() => Product)
  products: Product[];
}
AThe property 'products' should be a single Product, not an array
BThe decorator @ManyToOne should be @OneToMany
CThe relation callback function is missing
DThe entity 'Review' cannot have relations
Step-by-Step Solution
Solution:
  1. Step 1: Understand ManyToOne relation

    @ManyToOne means many Reviews relate to one Product, so the property should be a single Product.
  2. Step 2: Identify error

    The property products is declared as an array, which is incorrect for ManyToOne.
  3. Final Answer:

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

    @ManyToOne property is single entity [OK]
Quick Trick: @ManyToOne properties are single entities [OK]
Common Mistakes:
  • Declaring ManyToOne property as array
  • Confusing @ManyToOne with @OneToMany
  • Omitting inverse side in relation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes