Options
All
  • Public
  • Public/Protected
  • All
Menu

Options provided when associating models with belongsToMany relationship

see

Association class belongsToMany method

Hierarchy

Index

Properties

Optional as

as: string | object

The alias of this model, in singular form. See also the name option passed to sequelize.define. If you create multiple associations between the same tables, you should provide an alias to be able to distinguish between them. If you provide an alias when creating the assocition, you should provide the same alias when eager loading and when getting assocated models. Defaults to the singularized name of target

Optional constraints

constraints: boolean

Should on update and on delete constraints be enabled on the foreign key.

Optional foreignKey

foreignKey: string | AssociationForeignKeyOptions

The name of the foreign key in the target table or an object representing the type definition for the foreign column (see Sequelize.define for syntax). When using an object, you can add a name property to set the name of the column. Defaults to the name of source + primary key of source

Optional foreignKeyConstraint

foreignKeyConstraint: boolean

Optional hooks

hooks: boolean

Set to true to run before-/afterDestroy hooks when an associated model is deleted because of a cascade. For example if User.hasOne(Profile, {onDelete: 'cascade', hooks:true}), the before-/afterDestroy hooks for profile will be called when a user is deleted. Otherwise the profile will be deleted without invoking any hooks.

Defaults to false

Optional onDelete

onDelete: string

What happens when delete occurs.

Cascade if this is a n:m, and set null if it is a 1:m

Defaults to 'SET NULL' or 'CASCADE'

Optional onUpdate

onUpdate: string

What happens when update occurs

Defaults to 'CASCADE'

Optional otherKey

otherKey: string | AssociationForeignKeyOptions

The name of the foreign key in the join table (representing the target model) or an object representing the type definition for the other column (see Sequelize.define for syntax). When using an object, you can add a name property to set the name of the colum. Defaults to the name of target + primary key of target

Optional scope

A key/value set that will be used for association create and find defaults on the target. (sqlite not supported for N:M)

through

through: Model<any, any> | string | ThroughOptions

The name of the table that is used to join source and target in n:m associations. Can also be a sequelize model if you want to define the junction table yourself and add extra attributes to it.

In 3.4.1 version of Sequelize, hasMany's use of through gives an error, and on the other hand through option for belongsToMany has been made required.

see

https://github.com/sequelize/sequelize/blob/v3.4.1/lib/associations/has-many.js

see

https://github.com/sequelize/sequelize/blob/v3.4.1/lib/associations/belongs-to-many.js

Generated using TypeDoc