Documentation / zerotal / orm / hasOne
Function: hasOne()
hasOne(
related,options): (_value,context) =>void
Defined in: packages/orm/src/model/decorators/hasOne.ts:27
Declare a one-to-one relation: the parent owns a single related row, matched by
a foreign key on the related table (e.g. a User has one Profile).
Parameters
related
() => unknown
Lazy factory returning the related model class.
options
HasOneOptions
Foreign/local key configuration.
Returns
(_value, context) => void
Example
class User extends BaseModel {
\@hasOne(() => Profile, { foreignKey: 'user_id' })
profile!: HasOne<Profile>;
}