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.

Nested ordering on included models

See original GitHub issue

I want to accomplish ordering with deeply included models:

...
include: [{
  model: models.Child,
  as: "children",
  attributes: [...],
  order: "id DESC"
}]
...

It seems like a top-level order[] orders your top-level query by an included field, but I’d like to instead sort the included models. Is there a way to accomplish this?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Maks-Yaremenkocommented, Nov 2, 2017

Anyone know how to limit and offset by an ordered nested objects? =(

I am trying like this: but I am just got first 10 filtered users… Then I click on the second page and got next 10 filtered by users… Not by position model. =( Any suggestions? Thx

offset = params.perPage * params.page; (0 equeal to first page)
limit  = params.perPage; (10)
order = [[Models.position, 'value' ,params.sortDirection]];

user.findAndCountAll({
  where: conditions,
  limit: limit,
  offset: offset,
  order: order,
  attributes: {
    exclude: ['password']
  },
  include: [{ model: this._dbModels.position }]
});
0reactions
mzaidsecommented, Mar 24, 2019

@Maks-Yaremenko Same issue is happening with me. Did you find a solution?

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 >
Does the order of models (and so variables) matter in nested ...
Those are Type I or sequential sums of squares and yes, ordering generally matters. The sequence of tests is saying.
Read more >
Sequelize - order by joined models | DailyCoding
We added model to include and the same model is used in order params, where we declare that we want to order results...
Read more >
Sequelize — sort another Model in include by using order
I am using the postgres and sequelize the current project. I tried to join the team model with member model in a query,...
Read more >
Nested Ordered Sets and their Use for Data Modelling - arXiv
Keywords: data modelling, concept-oriented model, nested ordered sets, dimension, ... that an element can be included into projection only once even if many ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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