DEV Community

loizenai
loizenai

Posted on

Sequelize Many-to-Many association – NodeJS/Express, MySQL

https://grokonez.com/node-js/sequelize-many-to-many-association-nodejs-express-mysql

Sequelize Many-to-Many association – NodeJS/Express, MySQL

In the post, we got started with Sequelize One-To-Many association. Today we’re gonna create Sequelize Many-To-Many association models with NodeJS/Express, MySQL.

Related posts:

Sequelize Many-To-Many Association Express/Nodejs

Many-to-many association with a join table.

Note: When calling a method such as Project.belongsToMany(User, {through: 'UserProject'}), we say that the Project model is the source and the User model is the target.

We define 2 models:


const Project = sequelize.define('project', {
    /*
        attributes
    */
});

const User = sequelize.define('user', {
    /*
        attributes
    */
});

Many-To-Many associations are used to connect sources with multiple targets. And the targets can also have connections to multiple sources.

More at:

https://grokonez.com/node-js/sequelize-many-to-many-association-nodejs-express-mysql

Sequelize Many-to-Many association – NodeJS/Express, MySQL

Top comments (0)