title: Need to count a joined table rows sequelize
body: <p>I am using <code>sequelize</code> to query on a <code>sqlserver</code> database. I have two tables:</p>
  
  <pre><code>data: columns - id, name, team, type
  
  history:columns - id, node, date, status, data_id(foreignkey)
  </code></pre>
  
  <p>and a relation </p>
  
  <p><code>history.belongsTo(data, {foreignKey: 'data_id'}</code> </p>
  
  <p><code>data.hasMany(history, {foreignKey: 'data_id'})</code></p>
  
  <p>My query is:</p>
  
  <pre><code>dataModel.findAll({
      attributes: ['name'],
      include: [{
          model:historyModel
      }]
  })
  </code></pre>
  
  <p>My result looks like this: </p>
  
  <pre><code>[
      {
           name: "1",
           history: [
               {
                   ...
               }
           ]
      },
      {
           name: "2",
           history: [
               {
                   ...
               }
           ]
      }
  ]`
  </code></pre>
  
  <p>I want that instead of the history array I will have the count of history objects in each one. The query in <code>sql</code> is:</p>
  
  <pre><code>select data.name, count(history.data_id) count 
  from history 
  inner join data on data.id=history.data_id 
  group by history.data_id, data.name
  </code></pre>