我遇到了如何在NodeJS中制作降序主表的问题。我发展得像那样
models.Users.findAll({
where: {id: usersArray},
include: [
{model: models.Users_Answers}
],
order: [
[models.Users_Answers, 'id', 'ASC']
]
}).then(function(answers) {
/* Do something */
});
但是当我改变如下时遇到错误,遇到错误。
models.Users.findAll({
where: {id: usersArray},
include: [
{model: models.Users_Answers}
],
order: [
[models.Users, 'id', 'DESC']
[models.Users_Answers, 'id', 'ASC']
]
}).then(function(answers) {
/* Do something */
});
未处理拒绝错误:订单/组子句中的'用户'不是 有效的关联
答案 0 :(得分:2)
你需要这样做,
models.Users.findAll({
where: {id: usersArray},
include: [
{model: models.Users_Answers}
],
order: [
[db.Sequelize.col('id'), 'DESC'],
[models.Users_Answers, 'id', 'ASC']
]
}).then(function(answers) {
/* Do something */
});