Sequelize update nested associations

I have an instance where I have Users and Roles . I have the following:

  var User = sequelize.define("Users", {
    username: DataTypes.STRING,
    password: DataTypes.STRING,
  });

  var Role = sequelize.define("Role", {
    role: DataTypes.STRING
  });

  var UsersRole = sequelize.define("UsersRole");

  User.belongsToMany(Role, {through: UsersRole});

Which creates the UsersRoles table in the database for me with the UserId and RoleId columns. All this works great, but now I want to update the user role, I can’t decide how to do it! I tried the following with no luck:

models.Users.findAll({
    where: { id: req.params.id },
    include: [{ all: true }]
}).then(function(dbUser){
    dbUser[0].Roles[0].updateAttributes({
            RoleId: req.body.role,
        },
        {
            where: { UserId : req.params.id }
        }
    ).then(function (result) {...

In general, all I want to do is the ability to change the user role, so update the UsersRoles table and change the RoleId for this UserId . I can't figure out how to get to the UsersRoles table through any sequel syntax!

SQL, ?

, :

| UserId | RoleId |
-------------------
|    1   |    1   |

:

| UserId | RoleId |
-------------------
|    1   |    2   |

, !

+4
2

RoleId, . , Sequelize , id, id: req.body.role.

0

All Articles