inner join sequelize code example

Example 1: nested include sequelize

models.products.findAll({
  include: [
    {model: models.comments, include: [models.comments.users] }
  ]
})

Example 2: left join in sequelize

Shop.findAll({
     where:{id:shopId}, 
     include:[
         { model:ShopAd, as:'ads', 
           where:{ 
                 is_valid:1, 
                 is_vertify:1},   
           required:false
           }
         ]
      })
      .success(function(result) {
        callback(result);
    });

Example 3: sequelize left join attributes

Users.findAll({
    include: [
        {
            model: Role, 
            as: 'roles',
            attributes: ['columnNameToInclude']
        }
    ]
});

Tags:

Misc Example