@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
120 lines (69 loc) • 2.96 kB
Markdown
---
lang: en
title: 'API docs: sequelize.sequelizecrudrepository.createhasmanythroughrepositoryfactoryfor'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/extensions/sequelize
permalink: /doc/en/lb4/apidocs.sequelize.sequelizecrudrepository.createhasmanythroughrepositoryfactoryfor.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/sequelize](./sequelize.md) > [SequelizeCrudRepository](./sequelize.sequelizecrudrepository.md) > [createHasManyThroughRepositoryFactoryFor](./sequelize.sequelizecrudrepository.createhasmanythroughrepositoryfactoryfor.md)
## SequelizeCrudRepository.createHasManyThroughRepositoryFactoryFor() method
Function to create a constrained hasManyThrough relation repository factory
**Signature:**
```typescript
protected createHasManyThroughRepositoryFactoryFor<Target extends Entity, TargetID, Through extends Entity, ThroughID, ForeignKeyType>(relationName: string, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>> | {
[repoType: string]: Getter<EntityCrudRepository<Target, TargetID>>;
}, throughRepositoryGetter: Getter<EntityCrudRepository<Through, ThroughID>>): HasManyThroughRepositoryFactory<Target, TargetID, Through, ForeignKeyType>;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
relationName
</td><td markdown="1">
string
</td><td markdown="1">
Name of the relation defined on the source model
</td></tr>
<tr><td markdown="1">
targetRepositoryGetter
</td><td markdown="1">
Getter<EntityCrudRepository<Target, TargetID>> \| { \[repoType: string\]: Getter<EntityCrudRepository<Target, TargetID>>; }
</td><td markdown="1">
</td></tr>
<tr><td markdown="1">
throughRepositoryGetter
</td><td markdown="1">
Getter<EntityCrudRepository<Through, ThroughID>>
</td><td markdown="1">
</td></tr>
</tbody></table>
**Returns:**
HasManyThroughRepositoryFactory<Target, TargetID, Through, ForeignKeyType>
## Example
```ts
class CustomerRepository extends SequelizeCrudRepository<
Customer,
typeof Customer.prototype.id,
CustomerRelations
> {
public readonly cartItems: HasManyRepositoryFactory<CartItem, typeof Customer.prototype.id>;
constructor(
protected db: SequelizeDataSource,
cartItemRepository: EntityCrudRepository<CartItem, typeof, CartItem.prototype.id>,
throughRepository: EntityCrudRepository<Through, typeof Through.prototype.id>,
) {
super(Customer, db);
this.cartItems = this.createHasManyThroughRepositoryFactoryFor(
'cartItems',
cartItemRepository,
);
}
}
```