如何在sequelize中按ID排序
how to sort by ID in sequelize
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)
}
}
我正在尝试这种方式,但是这个消息出现在邮递员上
“'order clause' 中的未知列 'Postagens.DESC'”
order
选项应该是数组的数组,以防您希望指示排序方向,否则 Sequelize 会将平面数组视为列名数组:
const todasPostagens=await database.Postagens.findAll({order:
[['id','DESC']]
})
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)
}
}
我正在尝试这种方式,但是这个消息出现在邮递员上
“'order clause' 中的未知列 'Postagens.DESC'”
order
选项应该是数组的数组,以防您希望指示排序方向,否则 Sequelize 会将平面数组视为列名数组:
const todasPostagens=await database.Postagens.findAll({order:
[['id','DESC']]
})