class PostagemController {
static async pegaTodasPostagens(req,res){
try{
const todasPostagens=await database.Postagens.findAll({order:
['id','DESC']
})
return res.status(200).json(todasPostagens)
}catch (error){
return res.status(500).json(error.message)
}
}
我正在尝试这种方式,但此消息出现在 postman 身上“'订单条款'中的未知列'Postagens.DESC'”
最佳答案
order
选项应该是数组数组,以防您希望指示排序方向,否则 Sequelize 会将平面数组视为列名数组:
const todasPostagens=await database.Postagens.findAll({order:
[['id','DESC']]
})
关于sequelize.js - 如何在 Sequelize 中按 ID 排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67287623/