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

***

[Documentation](../../../../README) / [@zerotal/orm](../../README) / [index](../README) / hasManyThrough

# Function: hasManyThrough()

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

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

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

### related

() => `unknown`

Lazy factory returning the far/related model class.

### through

() => `unknown`

Lazy factory returning the intermediate model class.

### options

[`HasManyThroughOptions`](../interfaces/HasManyThroughOptions)

First/second key configuration across the two hops.

## Returns

(`_value`, `context`) => `void`

## Remarks

Not supported by has / whereHas; use eager
[with()](../classes/ModelQueryBuilder#with) to load it.

## Example

```ts
class Country extends BaseModel {
  \@hasManyThrough(() => Post, () => User, { firstKey: 'country_id', secondKey: 'user_id' })
  posts!: HasMany<Post>;
}
```
