gpt4 book ai didi

mysql - Sequelize - 嵌套模型中的 order by 不适用于 mysql

转载 作者:行者123 更新时间:2023-12-03 22:17:14 27 4
gpt4 key购买 nike

我的数据库中有 3 个模型:

Section (1:m) Sub_Section (1:m) Questions
这 3 个模型有一个名为 order 的字段,我想用它来排序我的数据。
但是,我无法为该协会使用 order by。
更新了代码
var SectionQuery = {
include: [{
model: sub_section,
order: [['order', 'asc']],
include: [{
model: question,
order: [['order', 'asc']],
}]
}]
};
return Section.findAll(tehsilQuery);

最佳答案

    var SectionQuery = {
include: [{
model: Section,
as: "section",
include: [{
model: Sub_Section,
as: "sub_section",
include: [{
model: Questions,
}]
}]
}],
order: [
[{model: Section, as: "section"}, "order", "asc"],
[{model: Section, as: "section"}, {model: Sub_Section, as: "sub_section"}, "order", "asc"]
]
};
return Sections.findAll(tehsilQuery);
这应该可以解决您的问题。

关于mysql - Sequelize - 嵌套模型中的 order by 不适用于 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66898110/

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