title: Sequelize optional where clause parameters?
body: <p>This is one thing that really annoys me! I have to write 2 different functions for almost the same query!</p>
  
  <p>Say I've got an API that returns <code>posts</code> that are associated to a particular <code>typeId</code> and <code>cityId</code>. To get <code>ALL</code> posts that are associated to <code>typeId 1 OR 2, OR 3</code> <strong><em>and</em></strong> <code>cityId 1</code> I would parse the following to my sequelize <code>findAll</code> query:</p>
  
  <pre><code>$or: [{typeId: 1}, {typeId: 2}, {typeId: 3}]
  cityId: 1
  </code></pre>
  
  <p>But say I want to get all post where <code>cityId = 1 andOr typeId = 1,2,3,4,5,6,7,8,9,10,etc...</code> I cannot do something like:</p>
  
  <pre><code>var types = [{typeId: 1}, {typeId: 2}, {typeId: 3}]
  Post.findAll({
       where: {
            if (types != []) $or: types,
            cityId: 1
        }
  </code></pre>
  
  <p>So instead I have to make a new query that won't include the <code>$or: types</code> where clause...Because if I parse an empty <code>types</code> array I get a weird <code>sql</code> output:</p>
  
  <pre><code>WHERE 0 = 1 AND `post`.`cityId` = '1'
  </code></pre>
  
  <p>Notice how it's outputting 0 = 1?! No idea why</p>