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