Q:

How to perform an sql query which joins another table for it's count() column in sequelizejs

Here is a raw sql query, I wonder how to perform it in sequelizejs
SELECT users.id, count(companies.area)
FROM users
LEFT JOIN companies
ON users.id = companies.user_id

thanks

A:

Here you go:
User.findAll({
  attributes: ['id', sequelize.fn('count', sequelize.col('companies.area'))],
  include: [Company]
});

