To use Sequelize findAll with sort order in Node.js, we call findAll
with an object with the order
property.
For instance, we write
const companies = Company.findAll({
where: {
id: [46128, 2865, 49569, 1488, 45600, 61991, 1418, 61919, 53326, 61680],
},
order: [
["id", "DESC"],
["name", "ASC"],
],
attributes: ["id", "logo_version", "logo_content_type", "name", "updated_at"],
});
to call findAll
with an object with the order
property to return the results sorted by id
descending and by name
ascending.