[**Documentation**](../../../README)

***

[Documentation](../../../README) / [zerotal](../../README) / [orm](../README) / hasOne

# Function: hasOne()

> **hasOne**(`related`, `options`): (`_value`, `context`) => `void`

Defined in: [packages/orm/src/model/decorators/hasOne.ts:27](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/decorators/hasOne.ts#L27)

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

```ts
class User extends BaseModel {
  \@hasOne(() => Profile, { foreignKey: 'user_id' })
  profile!: HasOne<Profile>;
}
```
