title: Sequelize: how to get flattened data, when joining table based on nested associations?
body: <p>I have relations defined like,</p>
  
  <pre><code>device_data.belongsTo(models.device)
  device.belongsTo(models.category)
  category.belongsTo(models.role)
  </code></pre>
  
  <p>What I am trying to get is all the device data which falls under a specific role. Right now I have the following working:</p>
  
  <pre><code>const query = {
      include: [{
          model: device,
          attributes: ['id'],
          include: [{
              model: category,
              attributes: ['id'],
              include: [{
                  model: role,
                  attributes: ['id'],
                  where: {
                      id: {
                          [Op.eq]: roleId,
                      },
                  },
                  required: true,
              }],
              required: true,
          }],
          required: true,
      }],
  };
  </code></pre>
  
  <p>Obviously, this gives returns me formatted data like following:</p>
  
  <pre><code>{
      "id": 1,
      "created_timestamp": "2019-08-12T12:28:36.194Z",
      "device_id": 1,
      "device_value": 0,
      "initiator_id": 2,
      "device": {
          "id": 1,
          "category": {
              "id": 1,
              "role": {
                  "id": 1
              }
          }
      }
  },
  </code></pre>
  
  <p>Where <code>role</code> is nested in 3rd level and the <code>role.id</code> in 4th.</p>
  
  <p>What I am trying to achieve is:</p>
  
  <pre><code>{
      "id": 1,
      "created_timestamp": "2019-08-12T12:28:36.194Z",
      "device_id": 1,
      "device_value": 0,
      "initiator_id": 2,
      "device": 1,
      "category": 1,
      "role": 1
  },
  </code></pre>
  
  <p>I would appreciate a lot if someone could point me a hint or possibly the query to generate data like this from sequelize. Thank you very much.</p>