title: Option.order is broken when passing it to class method
body: <h2>Background</h2>
  <pre><code>Error: Order must be type of array or instance of a valid sequelize method
  </code></pre>
  <p>I thought I've solved this issue but turns out that I mess up with this error again.</p>
  <p>I'm trying to make class method to calculate some properties for a model.
  Let this be Model A.</p>
  <p>Model A is associated with Model B. Because I have issue for generating proper column name for Model B when using array parameter.
  I'm planning to bypass this issue by using <code>sequelize.literal()</code></p>
  <hr />
  <h2>Pattern</h2>
  <ol>
  <li>Make a class method for Model A (a lot of business layer is used this function. So I can't take this away)</li>
  <li>Prototype of this method is <code>Model.function(options)</code>. This options object is validated inside of method function and if it needed mutated somehow.</li>
  <li>Validated option object is passed to  <code>Model.findAll(options)</code></li>
  </ol>
  <p>I'm impletmenting this solution as like code below</p>
  <h2>Router</h2>
  <pre class="lang-js prettyprint-override"><code>const sequelize = require('sequelize')
  const { ModelA } = require('../models')
  ...
  router.get('/', ..., async (req, res, next) =&gt; {
      try {
          ...
          if(page &lt; lastpage + 1){
              const products = await ModelA.classMethod({
                  subquery : false,
                  include: [
                     ...
                  ],
                  ...
                  order : sequelize.literal(`&quot;Product.rating&quot; DESC`)
              })
              
              ...
          }
          ...
      } catch (e) {
          ...
      }
  })
  </code></pre>
  <h2>Class method</h2>
  <pre><code>ModelA.classMethod = async function(options){
     const sequelize = require('sequelize')
     const { ModelB } = require('.')
  
     let { include, where, order, limit, offset, product } = options
      ...
  
      const items = await ModelA.findAll({
        subquery: false,
        include: [
          {
            model: ModelB,
            as: 'ModelB',
            required: true,
            where: product.where,
            include: include
          }
        ],
        where: where,
        limit: limit,
        order: order
      })
  
      ...
  }
  </code></pre>
  <p>Weird thing is happening here. While passing parameter (Pattern 3), I got an error <code>Error: Order must be type of array or instance of a valid sequelize method</code> and this error seems that because the option passed is invalid <code>sequelize.literal()</code></p>
  <p>But actually what I passed is just <code>sequelize.literal(`'Product.name' DESC`)</code>, no mutation in here.
  So I tried to figure out what's wrong with my literal.</p>
  <pre><code>let { order } = option
  
  console.log(order)//Literal { val: &quot;'Product.rating' DESC&quot; }
  console.log(order instanceof sequelize.Utils.SequelizeMethod)//false
  
  if(!order) order = null
  
  console.log(order)//Literal { val: &quot;'Product.rating' DESC&quot; }
  
  ModelA.findAll({ ..., order : order })
  
  console.log('good!!!')//I want to see this log
  </code></pre>
  <p>Order itself looks fine but I think somewhere of prototype is broken.
  The most weired part is if I replace the order with <code>sequelize.literal(`'Product.name' DESC`)</code>
  ,which is the same as what I passed into classMethod parameter, some kind of magic happens and error is gone.</p>
  <pre><code>const sequelize = require('sequelize')
  let order = sequelize.literal(&quot;'Product.rating'&quot;)
  
  console.log(order)//Literal { val: &quot;'Product.rating' DESC&quot; }
  console.log(order instanceof sequelize.Utils.SequelizeMethod)//true!!
  
  if(!order) order = null
  
  ModelA.findAll({ ..., order : order })
  
  console.log('good!!!')//I see this log and I can finally rest in peace.
  </code></pre>
  <hr />
  <p>If anyone has similar problem like me, would you please share some insight to solve this problem? So far I tried like below.</p>
  <ol>
  <li>Passing router sequelize instance to class method. <code>console.log(order instanceof sequelize.Utils.SequelizeMethod)//true </code> so seems not broken actual query is not executed somehow.</li>
  <li>Statically add <code>order : sequelize.literal(&quot;'Product.rating' DESC&quot;)</code> : work perfect but useless in production. This option should be dynanic so that user can control it.</li>
  </ol>