title: Where condition in nested include in Sequelize
body: <p>I have a model with 3 entities, Documents, Employees and Managers. A Document belongs to and Employee and an Employee belongs to a Manager.
  My objective is to retrieve all the documents of a manager employees.</p>
  
  <p>My piece of code is working</p>
  
  <pre><code>Document.findAll({
        include: [{
          model: models.Employee,
          required: true,
          as: 'employee',
          include: [{
            model: models.Manager,
            required: true,
            as: 'manager',
          }],
        }],
  </code></pre>
  
  <p>But I'm not really satisfied, I would like to have my where condition outside my include but when I try</p>
  
  <pre><code>where {
          'employee.manager.id': id
        }
  </code></pre>
  
  <p>an error is raised.</p>
  
  <p>Is it possible to setup a where condition outside the includes ? </p>
  
  <p>EDIT :</p>
  
  <p>I changed my code to</p>
  
  <pre><code>Document.findAll({
  where: {'$employee.manager.id$': id},
        include: [{
          model: models.Employee,
          required: true,
          as: 'employee',
          include: [{
            model: models.Manager,
            required: true,
            as: 'manager',
            where: { id: managerId },
          }],
        }],
  </code></pre>
  
  <p>and it's working.</p>
  
  <p>Now, I would like to refine my model. Each document as a type (administrative, evaluation ...) and I would like to retrieve the most recent document for each type for each manager. I used an order by which is working fine and tried to use a group by which is not working</p>
  
  <pre><code>order: [ [ 'updatedAt', 'DESC' ]],
  group: ['type'],
  </code></pre>
  
  <p>I get the following message : column \"Document.id\" must appear in the GROUP BY clause or be used in an aggregate function.</p>
  
  <p>Any idea what I'm doing wrong ?</p>