Skip to main content
zerotal

Documentation


Documentation / @zerotal/orm / index / hasManyThrough

Function: hasManyThrough()

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

Defined in: packages/orm/src/model/decorators/hasManyThrough.ts:35

Declare a has-many-through relation: reach the related rows across one intermediate ("through") model — e.g. Country —(users.country_id)→ User —(posts.user_id)→ Post, so a country has many posts through its users.

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 {
  \@hasManyThrough(() => Post, () => User, { firstKey: 'country_id', secondKey: 'user_id' })
  posts!: HasMany<Post>;
}