title: Sequelize include with multiple where condition
body: <p>I have a bit of problem for using Sequelize with <code>include</code>. The problem is that my model uses two primary keys in child table.</p>
  
  <p>So it goes like this 
  Parent table
  User : Id, ...<br>
  Post : Id, UserId(foreign key, binds to user id), ...
  Post Hash Tag : HashTag, PostId(foreign key, binds to Post id), UserId(foreign key, binds to user id of Post table)</p>
  
  <p>So the table hierarchy looks like this
  user - post - post hash tag</p>
  
  <p>Now when I try to do like this,</p>
  
  <pre><code>Post.findAll(
    include: {
      model: post hash tag
    }
  )
  </code></pre>
  
  <p>then it only searches the post hash tags for where post id of post hash tag table is equal to post id of post table</p>
  
  <p>So I added like this</p>
  
  <pre><code>Post.findAll(
    include: {
      model: post hash tag
      where: {
        col1: models.sequelize.where(models.sequelize.col('POST.USER_ID'), '=', models.sequelize.col('POST_HASH_TAG.USER_ID'))
      }
    }
  );
  </code></pre>
  
  <p>Then it will gives a problem at 'where' clause that Post.USER_ID cannot be found.</p>
  
  <p>If I change col1 value to Post.userId then now it solves the above error but gives another error at 'on' clause</p>
  
  <p>Do you have any idea how I can solve this?</p>
  
  <p>The full model is given here</p>
  
  <p>User</p>
  
  <pre><code>sequelize.define('User', {
      id: { type: DataTypes.STRING(6), field: 'ID', primaryKey : true }
  )
  </code></pre>
  
  <p>Post - I know multiple primary declaration is not working correctly, so don't bother to consider too much</p>
  
  <pre><code>sequelize.define('Post', {
      id: { type: DataTypes.STRING(6), field: 'ID', primaryKey: true },
      userId: { type: DataTypes.STRING(6), field: 'USER_ID', primaryKey: true }
  )
  </code></pre>
  
  <p>Post hash tag</p>
  
  <pre><code>sequelize.define('PostHashTag', {
      postId: { type: DataTypes.STRING(6), field: 'POST_ID', primaryKey: true },
      hashTag: { type: DataTypes.STRING(20), field: 'HASH_TAG', primaryKey: true },
      userId: { type: DataTypes.STRING(6), field: 'USER_ID', primaryKey: true }
    }
  )
  </code></pre>
  
  <p>and the query I used is</p>
  
  <pre><code>Post.findAll({
    attributes: ['id', 'userId'],
    where: {
      userId: userId,
      id: { $lt: postId }
    },
    include: [{
      model: models.PostHashTag,
      attributes: ['hashTag'],
      where: {
        col1: models.sequelize.where(models.sequelize.col('Post.USER_ID'), '=', models.sequelize.col('PostHashTag.userId'))
    }]).then(...)
  </code></pre>