Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize js - limit and Sorting bug

What is the proper way to sort the query in sequelize js?

example:

db.model.findAll({ 
    where: conditions, 
    order: 'postDate DESC', 
    limit: 10, 
    offset: 0, 
    include: [model1, model2] 
}).complete(function(err, results){console.log(results); });

Resulting in pulling the results of the limit and offset, first and then it does the sorting. What should I do to do the sorting first before limiting the results?


in the future who will encounter this bug, this is the fix

order: [["postDate","DESC"]]
like image 315
Gingy Avatar asked Mar 20 '14 13:03

Gingy


1 Answers

You have to specify it like this: order: [["postDate","DESC"]]

like image 179
Farid Nouri Neshat Avatar answered Nov 14 '22 02:11

Farid Nouri Neshat