sequelize.js - 如何在sequelize中按ID排序
问题描述
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)
}
}
我正在尝试这种方式,但此消息出现在邮递员身上
“‘订单子句’中的未知列‘Postagens.DESC’”
解决方案
该order
选项应该是数组数组,以防您希望指示排序方向,否则 Sequelize 将平面数组视为列名数组:
const todasPostagens=await database.Postagens.findAll({order:
[['id','DESC']]
})
推荐阅读
- javascript - Panresponder + 插值
- python - 如何解压不可迭代的项目?
- axios - 在移动设备上使用 tns preview 或 tns preview --bundle axios 不起作用
- asp.net-core - asp.net core Identity 15 分钟后自动注销?
- spring - Spring MVC 对移动设备和标准浏览器的支持
- kubernetes - 使用 traefik 入口访问 kibana
- mysql - R 和 DBI dbWriteTable 与 MySQL/MariaDB 的连接仅导入第一行
- html - 将按钮的索引值传递给弹出框组件
- python - 我可以用 xlwings 和 python 在 excel 中创建一个表吗?
- sql - SQL - 每个用户最近完成的五门培训课程