Shrikant
Shrikant

Reputation: 538

How to order by in eager loading on order field in sequelize?

here is my code:- in sequelize how to order in eager loading. by order field

.findAll({
  include: [{
    model: db.tab,
    include: [{
      model: db.column,
      include: [{
        model: db.tabelement
      }]
    }, {
      model: db.tabbrand
    }]
  }],
  order: [
    [db.Sequelize.col('order'), 'ASC'],
    [db.tab, db.column, db.tabelement, 'order', 'ASC']
  ]
})

Upvotes: 1

Views: 536

Answers (1)

Shrikant
Shrikant

Reputation: 538

return db.menu
.findAll({
  include: [{
    model: db.tab,
    include: [{
      model: db.column,
      include: [{
        model: db.tabelement
      }]
    }, {
      model: db.tabbrand
    }]
  }],
  order: [
    [db.Sequelize.col('order'), 'ASC'],
    [db.tab, 'order', 'ASC'],
    [db.tab, db.column, 'order', 'ASC'],
    [db.tab, db.column, db.tabelement, 'order', 'ASC']
  ]
})

Upvotes: 1

Related Questions