Page Contents

Home > @loopback/sequelize > SequelizeCrudRepository > createHasManyRepositoryFactoryFor

SequelizeCrudRepository.createHasManyRepositoryFactoryFor() method

Function to create a constrained relation repository factory

Signature:

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

Parameters

Parameter Type Description
relationName string Name of the relation defined on the source model
targetRepositoryGetter Getter<EntityCrudRepository<Target, TargetID>>  

Returns:

HasManyRepositoryFactory<Target, ForeignKeyType>

Example

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

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