question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I apply order to includes

See original GitHub issue

I’ve been trying to use this syntax but it does not seem to work, any ideas?

    include: [
        { model: models.Image, as: 'IdeaHeaderImages', order: [['Image.updated_at','ASC']] }
    ]

From here: https://github.com/rbjarnason/your-priorities-app/blob/master/server_api/controllers/ideas.js#L97

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:65
  • Comments:55 (7 by maintainers)

github_iconTop GitHub Comments

298reactions
cbaroncommented, Nov 21, 2017

Yeah, the docs are really bad.

184reactions
mickhansencommented, Jul 29, 2021

That syntax is not currently supported (except with separate: true which only works for hasMany atm). You need to use the slighter longer/sweird syntax:

findAll({
  ...
  order: [
    [models.Image, 'updated_at', 'asc']
  ]
  ...
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Ordering results of eager-loaded nested models in ...
I need to be able to query the parent model 'Page' and include the associated models, and sort those associations by the field...
Read more >
Sequelize — sort another Model in include by using order
I tried to join the team model with member model in a query, and the member needed to be sort by workYears ascending...
Read more >
Sequelize - order by joined models | DailyCoding
To keep order in Sequelize we use order param. It gets an array of order specifications. These order specifications are also arrays, but...
Read more >
include order sequelize - Code Examples & Solutions For This ...
Accesses.findAll({ include: [{ model: StationTypes, as: 'StationTypes', }], order: [['StationTypes', 'Order', 'ASC']], where: { ... }, }).then(...)
Read more >
Ordering with included models | GoRails
Ordering with included models ... I am able to sort them by either numerical value or the related item name from the product...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found