title: Use value in query to define the where of a sub query using sequelize
body: <p>I am wanting to use the year column of the episode table to use in the where of the progress table with out doing two queries. Is this possible with Sequelize?</p>
  
  <p>Here is the query I am running. Currently it is using a static year and I would like it to be dynamically generated based of the episodes year.</p>
  
  <pre><code>// Associations
  models.Episode.belongsTo(models.Unit, {foreignKey: 'unitId', targetKey: 'unitId'})
  models.Unit.belongsToMany(models.Badge, {through: 'unitToBadge'})
  models.Badge.belongsToMany(models.Unit, {through: 'unitToBadge'})
  models.Badge.hasOne(models.Progress, {foreignKey: 'badgeId', targetKey: 'badgeId'})
  
  // Get Episode-&gt;Unit-&gt;UnitToBadge-&gt;Badge-&gt;Progress from episodeId
  const episode = await models.Episode.findOne({
    where: {
      episodeId: episodeId,
      unitId: {
        [Sequelize.Op.not]: null
      }
    },
    include: [
      {
        model: models.Unit,
        include: [
          {
            model: models.Badge,
            include: [
              {
                model: models.Progress,
                where: {
                  userId: userId,
                  complete: false,
                  year: 2019  // TODO need to get the year dynamicly from episode
                }
              }
            ]
          }
        ]
      }
    ]
  })
  </code></pre>
  
  <p>This is the episode table model</p>
  
  <pre><code>const episode = (sequelize, DataTypes) =&gt; {
      const Episode = sequelize.define('episode', {
        episodeId: {
          type: DataTypes.INTEGER,
          unique: true
        },
        year: {
          type: DataTypes.INTEGER,
        },
        unitId: {
          type: DataTypes.INTEGER
        },
        updatedAt: {
          type: DataTypes.DATE(6),
          allowNull: true,
          defaultValue: sequelize.fn('NOW')
        },
        createdAt: {
          type: DataTypes.DATE(6),
          allowNull: true,
          defaultValue: sequelize.fn('NOW')
        }
      }, {
        indexes: [
          {
            unique: false,
            fields: ['updatedAt']
          }
        ]
      })
  
      return Episode
    }
  
    export default episode;
  </code></pre>