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 Type Description
keyFrom? string (Optional)
keyTo? string (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.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”.
targetsMany true  
through? { model: TypeResolver<Entity, typeof Entity>; keyFrom?: string; keyTo?: string; polymorphic?: boolean | { discriminator: string; }; } (Optional) Description of the through model of the hasManyThrough relation.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.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 RelationType.hasMany