title: WHERE OR WHERE THROUGH in Sequelize
body: <p>so i have 3 tables : 
  <strong>Post</strong> , <strong>Pivot</strong> , <strong>Category</strong></p>
  
  <p>in the <strong>Post</strong> table there is a field for main category = <strong>main_category_id</strong> post can have one Main Category at a time.</p>
  
  <p>and then the <strong>Pivot</strong> table serve as pivot for Secondary Category which the post can have more than 1.</p>
  
  <p>fields in <strong>Pivot</strong></p>
  
  <ul>
  <li>post_id</li>
  <li>category_id</li>
  </ul>
  
  <p>I'm trying to get the <strong>Post</strong> where the <strong>main_category = id</strong> or where the pivot have <strong>category_id = id</strong></p>
  
  <p>Current code : </p>
  
  <pre><code>var mainPost = await models.t_post.findAll({
          where:{
              main_category_id:main.id
          },
          include: [{
              model: models.m_category,
              as:"secondary_category",
              through: { 
                  where: {category_id: main.id},
              },
              attributes: ['id']
          }],
          order:[
              ['createdAt',"desc"]
          ],
          limit:limit,
          offset:3+(limit*page)-limit,
      })
  </code></pre>
  
  <p>EDIT : Added models</p>
  
  <p>Post Model</p>
  
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; {
    const T_Post = sequelize.define('t_post', {
      user_id: DataTypes.INTEGER,
      title: DataTypes.STRING,
      subtitle: DataTypes.STRING,
      content: DataTypes.TEXT,
      excerpt: DataTypes.TEXT,
      thumbnail: DataTypes.STRING,
      thumbnail_caption: DataTypes.STRING,
      slug: DataTypes.STRING,
      permalink: DataTypes.STRING,
      template: DataTypes.INTEGER,
      published: DataTypes.BOOLEAN,
      published_date: DataTypes.DATE, 
    }, {
      timestamps: true,
      paranoid:true,
      underscored: true,
      freezeTableName: true,
      tableName: 't_post',
      paranoid: true,
    });
    return T_Post;
  };
  </code></pre>
  
  <p>Pivot Model</p>
  
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; {
    const m_post_category = sequelize.define('m_post_category', {
      category_id: DataTypes.INTEGER,
      post_id: DataTypes.INTEGER,
    }, {
      timestamps: true,
      paranoid:true,
      underscored: true,
      freezeTableName: true,
      tableName: 'm_post_category'
    });
    return m_post_category;
  };
  </code></pre>
  
  <p>Category Model</p>
  
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; {
    const m_category = sequelize.define('m_category', {
      name: DataTypes.STRING,
      slug: DataTypes.STRING,
      template_id: DataTypes.STRING,
      is_active: DataTypes.BOOLEAN,
      has_title: DataTypes.BOOLEAN,
      has_sub_menu: DataTypes.BOOLEAN,
    }, {
      timestamps: true,
      paranoid:true,
      underscored: true,
      freezeTableName: true,
      tableName: 'm_category'
    });
    return m_category;
  };
  </code></pre>
  
  <p>Association</p>
  
  <pre><code>//Get Main category in this post
  t_post.belongsTo(m_category,{
    foreignKey:"main_category_id",
    as:"main_category"
  })
  
  //Get secondary category in this post
  t_post.belongsToMany(m_category,{
    through: m_post_category,
    as: 'secondary_category',
    foreignKey: 'post_id'
  })
  
  //Get post that have this category as secondary category
  m_category.belongsToMany(t_post,{
    through: m_post_category,
    as: 'article_as_secondary',
    foreignKey: 'category_id'
  })
  
  //Eager Loading get post with this category **category.posts**
  m_category.hasMany(t_post,{
    as:"posts",
    foreignKey:"main_category_id"
  })
  </code></pre>