Skip to main content
zerotal

Documentation


Documentation / zerotal / orm / hasOneThrough

Function: hasOneThrough()

hasOneThrough(related, through, options): (_value, context) => void

Defined in: packages/orm/src/model/decorators/hasOneThrough.ts:25

Declare a has-one-through relation: reach a single related record across one intermediate ("through") model (the one-to-one counterpart of hasManyThrough).

Parameters

() => unknown

Lazy factory returning the far/related model class.

through

() => unknown

Lazy factory returning the intermediate model class.

options

HasManyThroughOptions

First/second key configuration across the two hops.

Returns

(_value, context) => void

Remarks

Not supported by has / whereHas; use eager with() to load it.

Example

class Country extends BaseModel {
  \@hasOneThrough(() => Post, () => User, { firstKey: 'country_id', secondKey: 'user_id' })
  latestPost!: HasOne<Post>;
}