title: Unable to sort sequlize results based on joined table fields
body: <p>I am working with 3 sequelize models as described below:</p>
  
  <pre><code>tags:
  id
  tag_name
  
  product_tags:
  id
  tag_id --&gt; Foreign Key 'id' from tags
  product_id --&gt; Foreign Key 'id' from products
  tag_score
  
  products:
  id
  name
  </code></pre>
  
  <p>I wanted to get the product names along with their associated tags and the tag score and sort them by the score, as described in the SQL query below.</p>
  
  <pre><code>select t.tag_name, p.name, pt.tag_score from tags t inner join product_tags pt on t.id = pt.tag_id inner join products p on pt.product_id = p.id order by pt.tag_score desc;
  </code></pre>
  
  <p>As per the sequelize documentation,this can be accomplished by an order clause like so:</p>
  
  <pre><code>order: [this.db.ProductTag, 'tag_score', 'DESC']
  </code></pre>
  
  <p>However, I get the error message: Unable to find a valid association for model, 'ProductTag'</p>
  
  <p>Can someone please point out what I'm missing here?</p>
  
  <p>EDIT: 
  Sequelize query is below:</p>
  
  <pre><code>return this.db.Product.findAll({
    attributes: ['name'],
    include: [
      {
        model: this.db.Tag,
        as: 'tags',
        through: this.db.ProductTag,
        foreignKey: 'tag_id',
        otherKey: 'product_id',
        where: {
          tag_name: {
            $regexp: regexString
          }
        },
        required: true,
        include: [
          {
            model: this.db.ProductTag,
            as: 'product_tags',
            attributes: ['tag_score']
          }
        ]
      }
    ],
    order: [this.db.ProductTag, 'tag_score', 'DESC']
  });
  </code></pre>