Bird
0
0

Given these NestJS TypeORM entities:

medium📝 component behavior Q4 of 15
NestJS - Database with TypeORM
Given these NestJS TypeORM entities:
class Category {
  @OneToMany(() => Product, product => product.category)
  products: Product[];
}

class Product {
  @ManyToOne(() => Category, category => category.products)
  category: Category;
}

What type will category.products have when loaded?
AUndefined
BA single Product entity
CA Promise resolving to a Product
DAn array of Product entities
Step-by-Step Solution
Solution:
  1. Step 1: Analyze relation

    The @OneToMany decorator defines a one-to-many relation, so products is a collection.
  2. Step 2: Determine type

    Since one Category can have many Products, category.products will be an array of Product entities.
  3. Final Answer:

    An array of Product entities -> Option D
  4. Quick Check:

    @OneToMany always returns an array [OK]
Quick Trick: @OneToMany properties are arrays [OK]
Common Mistakes:
  • Assuming @OneToMany returns a single entity
  • Confusing @ManyToOne with @OneToMany types
  • Thinking it returns a Promise instead of array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes