Optional
pair: BelongsToMany<TargetModel, SourceModel, ThroughModel, TargetKey, SourceKey>Optional
parent: Association<any, Model<any, any>, string, NormalizedAssociationOptions<string>>Private
#privateReadonly
accessorsReadonly
fromReadonly
fromReadonly
optionsThe corresponding association this entity is paired with.
Readonly
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 corresponding column name of otherKey
use foreignKey
The corresponding column name of foreignKey
negate isMultiAssociation instead
The name of the Foreign Key attribute, located on the through table, that points to the Target model.
Not to be confused with
, which points to the Source model 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 that the foreignKey fk (located on the Through Model) will reference on the Source model.
The name of the Column that the foreignKey fk (located on the Through Table) will reference on the Source model.
The name of the Attribute that the otherKey fk (located on the Through Model) will reference on the Target model.
The name of the Column that the otherKey fk (located on the Through Table) will reference on the Target model.
Static
isAssociate one or several rows with source instance. It will not un-associate any already associated instance
that may be missing from newInstances
.
source instance to associate new instances with
A single instance or primary key, or a mixed array of persisted instances or primary keys
Optional
options: BelongsToManyAddAssociationsMixinOptions<TargetModel>Options passed to through.findAll
, bulkCreate
and update
Count everything currently associated with this, using an optional where clause.
instance
Optional
options: BelongsToManyCountAssociationsMixinOptions<TargetModel>find options
Create a new instance of the associated model and associate it with this.
source instance
Optional
values: CreationAttributes<TargetModel>values for target model
Optional
options: BelongsToManyCreateAssociationMixinOptions<TargetModel> | (keyof Attributes<TargetModel>)[]Options passed to create and add
Get everything currently associated with this, using an optional where clause.
See Model for a full explanation of options
instance
Optional
options: BelongsToManyGetAssociationsMixinOptions<TargetModel>find options
Check if one or more instance(s) are associated with this. If a list of instances is passed, the function returns true if all instances are associated
source instance to check for an association with
Can be an array of instances or their primary keys
Optional
options: BelongsToManyHasAssociationMixinOptions<TargetModel>Options passed to getAssociations
Un-associate one or more instance(s).
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: BelongsToManyRemoveAssociationMixinOptionsOptions passed to through.destroy
Set the associated models by passing an array of instances or their primary keys. Everything that it not in the passed array will be un-associated.
source instance to associate new instances with
A single instance or primary key, or a mixed array of persisted instances or primary keys
Optional
options: BelongsToManySetAssociationsMixinOptions<TargetModel>Options passed to through.findAll
, bulkCreate
, update
and destroy
Private
toPrivate
Normalize input
built objects
it may be array or single obj, instance or primary key
Static
associateOptional
pair: BelongsToMany<T, S, ThroughModel, TargetKey, SourceKey>Optional
parent: Association<any, Model<any, any>, string, NormalizedAssociationOptions<string>>Generated using TypeDoc
Many-to-many association with a join/through table. See belongsToMany
When the join table has additional attributes, these can be passed in the options object:
All methods allow you to pass either a persisted instance, its primary key, or a mixture:
If you want to set several target instances, but with different attributes you have to set the attributes on the instance, using a property with the name of the through model:
Similarly, when fetching through a join table with custom attributes, these attributes will be available as an object with the name of the through model.
In the API reference below, add the name of the association to the method, e.g. for
User.belongsToMany(Project)
the getter will beuser.getProjects()
.