Ordering results of eager-loaded nested models in Node Sequelize

I believe you can do:

db.Page.findAll({
  include: [{
    model: db.Gallery
    include: [{
      model: db.Artwork
    }]
  }],
  order: [
    // sort by the 'order' column in Gallery model, in descending order.

    [ db.Gallery, 'order', 'DESC' ], 


    // then sort by the 'order' column in the nested Artwork model in a descending order.
    // you need to specify the nested model's parent first.
    // in this case, the parent model is Gallery, and the nested model is Artwork

    [ db.Gallery, db.ArtWork, 'order', 'DESC' ]
  ]
})

There are also a bunch of different ways, or things you can do when ordering. Read more here: https://sequelize.org/master/manual/model-querying-basics.html#ordering-and-grouping

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)