首页 > 解决方案 > 如何在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’”

标签: sequelize.js

解决方案


order选项应该是数组数组,以防您希望指示排序方向,否则 Sequelize 将平面数组视为列名数组:

const todasPostagens=await database.Postagens.findAll({order:
                        [['id','DESC']]
                })

推荐阅读