postgresql - 为什么续集包含顺序不起作用?
问题描述
我已经阅读了几个提到排序的问题,包括续集中的模型,但没有找到任何可以解决我的问题的问题。这个案子似乎很简单,所以我遗漏了一些东西,但不知道是什么......
任何帮助将不胜感激。
定义:
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 排序的。
版本
续集:6.5.1 PostgreSQL:13.1
解决方案
我完全错过了订单的位置(在根而不是包含)。我的错。
推荐阅读
- javascript - HTML/JS 用户输入
- javascript - 函数不会更改 IE10-11 中元素的文本
- excel - 在 Excel get&transform 中从 XML 数据源展开可变数量的文本标签
- python - 我没有得到我应该在 for 循环中的内容(错误的数字)
- prometheus - 如何在 grafana 上显示指标时用标签替换目标
- java - Tizen 包管理器无法识别 JDK
- r - 将 2 列与数据名 R 的其余部分进行转置
- typescript - 联合类型:Typescript 抱怨“函数缺少结束返回语句并且返回类型不包括‘未定义’。(2366)”
- python-3.x - 升级到 Python 3.7
- javascript - 点击获取innerhtml到js函数的列表项