Function: BelongsTo()
BelongsTo(
target,options):PropertyDecorator
Defined in: src/decorators/BelongsTo.ts:22
Property decorator establishing a child-to-parent inverse relationship.
Enables eager loading through context.set(Child).include('user') or lazy loading via LazyRelation.
Parameters
| Parameter | Type | Description |
|---|---|---|
target | () => Function | Lambda returning the parent entity constructor. |
options | string | BelongsToOptions | Foreign key property on this child entity pointing to the parent. |
Returns
PropertyDecorator
Usecase
Model child-to-parent associations (e.g. Post belongs to User, OrderItem belongs to Order).
Example
@BelongsTo(() => User, { foreignKey: 'userId', lazy: true })
user?: LazyRelation<User>;