title: Formal and correct syntax to sort a field from the joined table using Sequelize.js findAll
body: <p>I have two tables - <code>Customer</code> and <code>Orders</code> which are in one-to-many relationship. I'm querying both tables using <a href="http://sequelize.readthedocs.org/en/latest/docs/models/#findall-search-for-multiple-elements-in-the-database" rel="nofollow">findAll()</a> and trying to sort <code>Orders.orderDate</code> by descending. The following are all wrong and result query error.</p>
  
  <h3>Wrong Syntax (1)</h3>
  
  <pre class="lang-js prettyprint-override"><code>Customer.findAll({
      order: [["orderDate", "DESC"]],
      include: [Order]
  }, {
      raw: true
  }).then(function(data) {
      console.log(data);
  }); 
  // Generated order by clause
  // ORDER BY "Customer"."orderDate" DESC;
  </code></pre>
  
  <h3>Wrong Syntax (2)</h3>
  
  <pre class="lang-js prettyprint-override"><code>Customer.findAll({
      order: [["Orders.orderDate", "DESC"]],
      include: [Order]
  }, {
      raw: true
  }).then(function(data) {
      console.log(data);
  }); 
  // Generated order by clause
  // ORDER BY "Customer"."Orders"."orderDate" DESC;
  </code></pre>
  
  <h3>Wrong Syntax (3)</h3>
  
  <pre class="lang-js prettyprint-override"><code>Customer.findAll({
      order: ["Orders.orderDate", "DESC"],
      include: [Order]
  }, {
      raw: true
  }).then(function(data) {
      console.log(data);
  });
  // Generated order by clause
  // ORDER BY "Orders"."orderDate", "DESC";
  </code></pre>
  
  <h3>Wrong Syntax (4)</h3>
  
  <pre class="lang-js prettyprint-override"><code>Customer.findAll({
      order: ["Orders.orderDate DESC"],
      include: [Order]
  }, {
      raw: true
  }).then(function(data) {
      console.log(data);
  });
  // Generated order by clause
  // ORDER BY "Orders"."orderDate DESC";
  </code></pre>
  
  <p>The following is the one I got it working:</p>
  
  <pre class="lang-js prettyprint-override"><code>Customer.findAll({
      order: '"Orders"."orderDate" DESC',
      include: [Order]
  }, {
      raw: true
  }).then(function(data) {
      console.log(data);
  });
  // Generated order by clause
  // ORDER BY "Orders"."orderDate" DESC;
  </code></pre>
  
  <p>However, I suspect that it could not be a formal and correct one as I have to add the double quotes manually. Quotes around table names an field names are automatically added in the above wrong syntax examples.</p>
  
  <p>I'm using Sequelize 2.0.0-rc3 with PostgreSQL.</p>