当我将sequelize ORM查询传递给nodejs服务器时,结果将不排序返回。我希望ID列按DESC排序。
// FETCH All Customers
exports.findAll = (req, res) => {
Section.findAll({
order: [["id", 'DESC']]
}).then(sections => {
// Send All Customers to Client
res.json(sections.sort(function(c1, c2){return c1.id - c2.id}));
}).catch(err => {
console.log(err);
res.status(500).json({msg: "error", details: err});
});
};
结果以升序而不是降序返回。
答案 0 :(得分:0)
删除次级排序功能,因为已经进行了排序:
// FETCH All Customers
exports.findAll = (req, res) => {
Section.findAll({
order: [["id", 'DESC']]
}).then(sections => {
// Send All Customers to Client
res.json(sections);
}).catch(err => {
console.log(err);
res.status(500).json({msg: "error", details: err});
});
};