Function: HasMany()
HasMany(
target,options):PropertyDecorator
Defined in: src/decorators/HasMany.ts:22
Property decorator establishing a one-to-many relationship with another entity.
Enables eager loading through context.set(Parent).include('children') or lazy loading via LazyRelation.
Parameters
| Parameter | Type | Description |
|---|---|---|
target | () => Function | Lambda returning the child entity constructor. |
options | string | HasManyOptions | Foreign key property on the child entity pointing to this parent, or options object. |
Returns
PropertyDecorator
Usecase
Model one-to-many associations (e.g. User has many Posts, Order has many Items).
Example
@HasMany(() => Post, { foreignKey: 'userId', lazy: true })
posts!: LazyRelation<Post[]>;