---
lang: en
title: 'API docs: repository.defaultcrudrepository.createhasmanyrepositoryfactoryfor'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.repository.defaultcrudrepository.createhasmanyrepositoryfactoryfor.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/repository](./repository.md) &gt; [DefaultCrudRepository](./repository.defaultcrudrepository.md) &gt; [createHasManyRepositoryFactoryFor](./repository.defaultcrudrepository.createhasmanyrepositoryfactoryfor.md)

## DefaultCrudRepository.createHasManyRepositoryFactoryFor() method

Function to create a constrained relation repository factory

<b>Signature:</b>

```typescript
protected createHasManyRepositoryFactoryFor<Target extends Entity, TargetID, ForeignKeyType>(relationName: string, targetRepoGetter: Getter<EntityCrudRepository<Target, TargetID>>): HasManyRepositoryFactory<Target, ForeignKeyType>;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  relationName | <code>string</code> | Name of the relation defined on the source model |
|  targetRepoGetter | <code>Getter&lt;EntityCrudRepository&lt;Target, TargetID&gt;&gt;</code> |  |

<b>Returns:</b>

`HasManyRepositoryFactory<Target, ForeignKeyType>`

## Example


```ts
class CustomerRepository extends DefaultCrudRepository<
  Customer,
  typeof Customer.prototype.id,
  CustomerRelations
> {
  public readonly orders: HasManyRepositoryFactory<Order, typeof Customer.prototype.id>;

  constructor(
    protected db: juggler.DataSource,
    orderRepository: EntityCrudRepository<Order, typeof Order.prototype.id>,
  ) {
    super(Customer, db);
    this.orders = this._createHasManyRepositoryFactoryFor(
      'orders',
      orderRepository,
    );
  }
}

```


