The model on which Model.hasMany has been called, on which the association methods will be added.
The model passed to Model.hasMany. This model will receive the Foreign Key attribute.
The name of the attribute that the foreign key in the target model will reference.
The name of the Foreign Key attribute on the Target model.
The name of the Primary Key attribute of the Target model. Used by HasManySetAssociationsMixin & others.
Optional
parent: Association<Model<any, any>, Model<any, any>, string, NormalizedAssociationOptions<string>>Optional
inverse: BelongsToAssociation<T, S, TargetKey, SourceKey>Readonly
inverseReadonly
optionsReadonly
parentA reference to the association that created this one.
The identifier of the relation on the source model.
The type of the association. One of HasMany
, BelongsTo
, HasOne
, BelongsToMany
The column name of the foreign key (on the target model)
negate isMultiAssociation instead
Creating an associations can automatically create other associations. This returns the initial association that caused the creation of the descendant associations.
The name of the attribute the foreign key points to.
This key is on the Source Model. The Association.foreignKey is on the Target Model.
Static
isPrivate
#mixinAssociate one or more target rows with this
. This method accepts a Model / string / number to associate a single row,
or a mixed array of Model / string / numbers to associate multiple rows.
the source instance
Optional
rawTargetInstances: AllowIterable<T | Exclude<T[TargetPrimaryKey], any[]>>A single instance or primary key, or a mixed array of persisted instances or primary keys
Optional
options: HasManyAddAssociationsMixinOptions<T> = {}Options passed to target.update
.
Count everything currently associated with this, using an optional where clause.
the source instance
Optional
options: HasManyCountAssociationsMixinOptions<T>find & count options
Create a new instance of the associated model and associate it with this.
source instance
values for target model instance
Options passed to target.create
Get everything currently associated with this, using an optional where clause.
source instances
Optional
options: HasManyGetAssociationsMixinOptions<T>find options
Optional
options: HasManyGetAssociationsMixinOptions<T>Check if one or more rows are associated with this
.
the source instance
A list of instances or their primary keys
Optional
options: HasManyHasAssociationsMixinOptions<T>Options passed to getAssociations
Un-associate one or several target rows.
instance to un associate instances with
Can be an Instance or its primary key, or a mixed array of instances and primary keys
Options passed to target.update
Set the associated models by passing an array of persisted instances or their primary keys. Everything that is not in the passed array will be un-associated
source instance to associate new instances with
An array of persisted instances or primary key of instances to associate with this. Pass null
to remove all associations.
Optional
options: HasManySetAssociationsMixinOptions<T>Options passed to target.findAll
and update
.
Private
toPrivate
Normalize input
it may be array or single obj, instance or primary key
built objects
Protected
toStatic
associateOptional
parent: Association<any, Model<any, any>, string, NormalizedAssociationOptions<string>>Optional
inverse: BelongsToAssociation<T, S, TargetKey, SourceKey>
One-to-many association. See Model.hasMany
Like with HasOneAssociation, the foreign key will be defined on the target model.
In the API reference below, add the name of the association to the method, e.g. for
User.hasMany(Project)
the getter will beuser.getProjects()
. If the association is aliased, use the alias instead, e.g.User.hasMany(Project, { as: 'jobs' })
will beuser.getJobs()
.