Q: How to find data from mysql using sequalize(nodeJs) based on associations? I am working on a node js project with sequalize as my ORM for fetching data from mysql. In this, I have a requirement to find all roles for a given users.I have 3 tables in my database.
 1. all_users ( userId,userName, etc etc.. )
 2. all_roles (roleId, roleName, etc. etc. )
 3. user_to_role ( userId,roleId) - mapping table
Here one user can have multiple roles. In that case, there will be many entries for the same user in third table. My associations are like this.
User.belongsToMany(Role, {as: "Roles", through: "user_to_role"});

Now How can I find all the roles for a given user ? Thanks in advance

A: A simple findAll should do
User.findAll({
where: {user_id: <user_id> } 
  include: [Roles]
})

