The model on which hasMany has been called, on which the association methods will be added.
The model passed to 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>>Private
#privateReadonly
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 foreignKey is on the Target Model.
use sourceKey
Static
isAssociate 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: AllowArray<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
Optional
values: CreationAttributes<T>values for target model instance
Optional
options: HasManyCreateAssociationMixinOptions<T> | (keyof Attributes<T>)[]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
Can be an array 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
Optional
options: HasManyRemoveAssociationsMixinOptions<T>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
built objects
it may be array or single obj, instance or primary key
Static
associateOptional
options: HasManyOptions<SourceKey, TargetKey>Optional
parent: Association<any, Model<any, any>, string, NormalizedAssociationOptions<string>>Generated using TypeDoc
One-to-many association. See hasMany
Like with HasOne, 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()
.