Tehsil - > 1:m - > Ilr - > 1:m - > Patwar - > 1:m - >村庄
我想在我的所有四个模型上应用订单。
查询:
var tehsilQuery = {
include: [{
model: Ilr,
as: 'GirdawariKanoongo',
include: [{
model: Patwar,
as: 'GirdawariPatwar',
include: [{
model: Villages,
as: 'GirdawariVillages',
}]
}]
}],
order: [
['tehsil_name', 'ASC'],
[ {model: Ilr, as: 'GirdawariKanoongo'}, 'kanoongo_name', 'ASC'],
[ {model: Patwar, as: 'GirdawariPatwar'}, 'patwar_area', 'ASC'],
[ {model: Villages, as: 'GirdawariVillages'}, 'village_name', 'ASC'],
]
};
return Tehsils.findAll(tehsilQuery);
[Error: 'girdawari_patwar' in order / group clause is not valid association]
如果我从Patwar
删除Villages
和order
(lat两个模型),则按顺序工作。
答案 0 :(得分:3)
另一个嵌套排序的工作示例:
order: [
[ { model: chapterModel, as: 'Chapters' }, 'createdAt', 'ASC'],
[ { model: chapterModel, as: 'Chapters' },
{ model: partModel, as: 'Parts' }, 'createdAt', 'ASC']
],
其中part和chapter具有M:1关系。
答案 1 :(得分:2)
我解决了。
这是order
看起来的样子:
order: [
'tehsil_name',
'GirdawariKanoongo.kanoongo_name',
'GirdawariKanoongo.GirdawariPatwar.patwar_area',
'GirdawariKanoongo.GirdawariPatwar.GirdawariVillages.village_name'
]
我所要做的就是:在表格的关联中使用as
并将它们链接起来,然后column_name
应该适用order
。
答案 2 :(得分:0)
我们的场景是使用两个嵌套的List<String> lines = Files.readAllLines(pathToFile);
语句,其中最里面的嵌套没有正确排序。通过在include
的最高级别应用ordering
,我们能够成功返回有序对象。
我们的findAll
的模型关系如下:
调查属于很多问题
surveySet.findAll
答案 3 :(得分:0)
对于任何想知道如何使用对象样式定义来实现的人,这就是解决方法。 您可以在Sequelize documentation中找到有关订购的更多信息。
order: [
['tehsil_name', 'ASC'],
[ {model: Ilr, as: 'GirdawariKanoongo'}, 'kanoongo_name', 'ASC'],
[ {model: Ilr, as: 'GirdawariKanoongo'}, {model: Patwar, as: 'GirdawariPatwar'}, 'patwar_area', 'ASC'],
[ {model: Ilr, as: 'GirdawariKanoongo'}, {model: Patwar, as: 'GirdawariPatwar'}, {model: Villages, as: 'GirdawariVillages'}, 'village_name', 'ASC'],
]