title: How to add ORDER BY into sequelize method in NodeJS
body: <p>I have a nodeJS app accessing a MySQL database using Sequelize.</p>
  
  <p>There are two tables for users:   <code>user</code> and <code>user_password</code></p>
  
  <p>There are multiple entries for each user in <code>user_password</code> table if the user has changed their password at least once.  I want to validate a user via <code>findUserWithUsername(username)</code> as shown:</p>
  
  <pre><code>async findOne(query = {}, include = [] , attributes = ['id', 'username', 'email'] ) {
      const user = await db.user.findOne({include: include, where: query,  attributes: attributes});
      return user;
  }
  
  async findUserWithUsername(username) {
      const include = [
          {
              model: db.user_password,
              attributes: ['id','algorithm', 'password', 'salt'],
              order: 'id desc'
          }
      ];
      return await this.findOne({username: username}, include); // need to get last one since there could be multiples
  }
  </code></pre>
  
  <p>This is not working : <code>order: 'id desc'</code></p>
  
  <p>Basically, the tables are joined and the first password entry in<code>user_password</code> is returned, but <code>order: id desc</code> doesn't do anything...I still get the first (oldest) entry. Here's the query that's run now from the <code>findUserWithUsername()</code> method:</p>
  
  <pre><code>    SELECT `user`.`id`, `user`.`username`, `user`.`email`, 
     `user_password`.`id` AS `user_password.id`, 
     `user_password`.`algorithm` AS `user_password.algorithm`, 
     `user_password`.`password` AS `user_password.password`, 
     `user_password`.`salt` AS `user_password.salt` 
      FROM `user` AS `user` 
      LEFT OUTER JOIN `user_password` AS `user_password` 
      ON `user`.`id` = `user_password`.`user_id` WHERE `user`.`username` = 'joe' LIMIT 1
  </code></pre>
  
  <p>So....How can I add the sql equivalent of <code>ORDER BY id</code> to the <code>findUserWithUsername()</code> method?</p>