Page Contents

Home > @loopback/repository > HasManyDefinition

HasManyDefinition interface

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


export interface HasManyDefinition extends RelationDefinitionBase 

Extends: RelationDefinitionBase


Property Modifiers Type Description
keyFrom?   string (Optional)
keyTo?   string <p>(Optional) keyTo: The foreign key used by the target model for this relation. keyFrom: The source key used by the source model for this relation.</p><p>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 is keyFrom. keyFrom defaults to the id property of a model. Users can provide a custom source key name by setting “keyTo”.</p>
targetsMany   true  
through?   { model: TypeResolver<Entity, typeof Entity>; keyFrom?: string; keyTo?: string; polymorphic?: boolean | { discriminator: string; }; } <p>(Optional) Description of the through model of the hasManyThrough relation.</p><p>A hasManyThrough 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.</p><p>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).</p><p>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.</p>
type   RelationType.hasMany