Question

Post
  .findAll({where: {tag: 'news'}, limit: 10})
  .success(function(result) { ... })

How to insert the condition of sorting by date in my query with not using sequelize.query like

.findAll({ limit: 10, sort: [updatedAt, descending]})
Was it helpful?

Solution 2

Here's the syntax:

Post.findAll({ limit: 10, order: '"updatedAt" DESC' })

Here are more examples from the official documentation.

OTHER TIPS

@dankohn is correct and that will work but it is safer to use the following:

Post.findAll({ limit: 10, order: [['updatedAt', 'DESC']]});

as this

will escape updatedAt and validate DESC against a list of valid direction parameters

Following is more cleaner syntax

Post.findAll({ limit: 10, order: 'updatedAt DESC'});

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top