gpt4 book ai didi

postgresql - 为什么 Sequelize 包含顺序不起作用?

转载 作者:行者123 更新时间:2023-12-03 22:30:59 24 4
gpt4 key购买 nike

我已经阅读了几个提到在 sequelize 中订购包含模型的问题,但没有找到任何可以解决我的问题的问题。这个案子似乎很简单,所以我遗漏了一些东西,但不知道是什么......
任何帮助将不胜感激。
定义:

models.Account.belongsToMany(models.User, {through: 'AccountUser'});
models.User.belongsToMany(models.Account, {through: 'AccountUser'});

models.Account.hasMany(models.AccountUser)
models.AccountUser.belongsTo(models.Account)

models.User.hasMany(models.AccountUser)
models.AccountUser.belongsTo(models.User)
查询:
const user = await models.User.findOne({
where: {
code: userCode,
},
include: [
{
model: models.AccountUser,
order: [ ['lastLoginAt', 'desc'] ],
include: {
model: models.Account,
}
}
]
})
结果
AccountUser 数组不是按 DESC 排序而是按 ASC 排序。
版本
Sequelize :6.5.1
PostgreSQL:13.1

最佳答案

我完全错过了订单的位置(在根而不是包含中)。我的错。
Ordering results of eager-loaded models in Node Sequelize

关于postgresql - 为什么 Sequelize 包含顺序不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66984410/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com