title: Sequelize help in associations
body: <p>All, Attached below is a SQL query that I used as a raw query in sequelize and it worked fine. Now I am trying to setup it up with mixin associations in sequelize but unable to do so. Did go thru the help documentations but could not completely grasp the details. Maybe its just me. Anyway, attached below is the query that I am trying to rework. Would appreciate if anybody can throw some pointers or have some samples to help me rework this? Thanks in advance.</p>
  
  <pre><code>select cust.*, cust_role.id, cust_role.rolename, role.roletype
  from
  customer cust, customer_roles cust_role, roles role
  where
  cust.id = cust_role.user and
  cust_role.role = role.id and
  cust.id like '0123456' //customerId
  </code></pre>
  
  <p>table relationships</p>
  
  <pre><code>customer_roles has a foreign key to both roles and customer tables
  customer to customer_roles (1 to many), 
  customer_roles to roles (many to 1)
  </code></pre>
  
  <p>I am importing the models</p>
  
  <pre><code>var custModel = sequelize.import('../models/customer.js');
  var custRolesModel = sequelize.import('../models/customer_roles.js');
  var roleModel = sequelize.import('../models/roles.js');
  </code></pre>
  
  <p>trying to set the relationships</p>
  
  <pre><code>custModel.hasMany(custRolesModel);
  custRolesModel.belongsTo(custModel);
  
  roleModel.hasMany(custRolesModel);
  custRolesModel.belongsTo(roleModel);
  </code></pre>
  
  <p>and finally trying to get the customer..</p>
  
  <pre><code>custModel.findAll({
    include:[{
      model:custRolesModel,
      include:[{
        model:roleModel,
        where: {
          username:req.body.username
        },
        required:false
      }]
    }]
  }).then(function (result) {
  ......
  </code></pre>