---
lang: en
title: 'API docs: repository.hasmanydefinition'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/repository
permalink: /doc/en/lb4/apidocs.repository.hasmanydefinition.html
---

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

[Home](./index.md) &gt; [@loopback/repository](./repository.md) &gt; [HasManyDefinition](./repository.hasmanydefinition.md)

## HasManyDefinition interface

HasManyDefinition defines one-to-many relations and also possible defines many-to-many relations with through models.

<b>Signature:</b>

```typescript
export interface HasManyDefinition extends RelationDefinitionBase 
```
<b>Extends:</b> [RelationDefinitionBase](./repository.relationdefinitionbase.md)

## Properties

|  Property | Type | Description |
|  --- | --- | --- |
|  [keyFrom?](./repository.hasmanydefinition.keyfrom.md) | string | <i>(Optional)</i> |
|  [keyTo?](./repository.hasmanydefinition.keyto.md) | string | <i>(Optional)</i> keyTo: The foreign key used by the target model for this relation. keyFrom: The source key used by the source model for this relation.<!-- -->E.g. when a Customer has many Order instances, then keyTo is "customerId". Note that "customerId" is the default FK assumed by the framework, users can provide a custom FK name by setting "keyTo". And Customer.id is keyFrom. keyFrom defaults to the id property of a model. Users can provide a custom source key name by setting "keyTo". |
|  [targetsMany](./repository.hasmanydefinition.targetsmany.md) | true |  |
|  [through?](./repository.hasmanydefinition.through.md) | { model: [TypeResolver](./repository.typeresolver.md)<!-- -->&lt;[Entity](./repository.entity.md)<!-- -->, typeof [Entity](./repository.entity.md)<!-- -->&gt;; keyFrom?: string; keyTo?: string; polymorphic?: boolean \| { discriminator: string; }; } | <i>(Optional)</i> Description of the through model of the hasManyThrough relation.<!-- -->A <code>hasManyThrough</code> relation defines a many-to-many connection with another model. This relation indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model.<!-- -->E.g a Category has many Products, and a Product can have many Categories. CategoryProductLink can be the through model. Such a through model has information of foreign keys of the source model(Category) and the target model(Product).<!-- -->Warning: The hasManyThrough interface is experimental and is subject to change. If backwards-incompatible changes are made, a new major version may not be released. |
|  [type](./repository.hasmanydefinition.type.md) | [RelationType.hasMany](./repository.relationtype.md) |  |


