gpt4 book ai didi

sorting - Grails:多个嵌套关系的分离标准

转载 作者:行者123 更新时间:2023-12-02 14:49:21 25 4
gpt4 key购买 nike

我正在尝试按第3层关系对数据进行排序,但是我看不到它能正常工作。我已经成功使用别名来查询2级关系。这就是我的查询设置

def query = Application.where {}

query.createAlias("applicationDegrees", "appDegrees");
query.createAlias("applicationDegrees.degree", "degree");
query.createAlias("applicationDegrees.applicationDegreeMajors", "appMajors");
query.createAlias("applicationDegrees.applicationDegreeMajors.major", "major");


return query.list([sort: "degree.code", order: "desc"]); //WORKS
return query.list([sort: "major.code", order: "desc"]); //DOES NOT WORK

从上面的示例代码中可以看到,我可以按appDegrees和学位进行排序。当我尝试更进一步并根据与appDegrees关系的appMajors或major进行排序时,它无法正确排序。根本不应用排序,但也不会引发任何错误消息。

这是我的数据模型
class Application {
Set<ApplicationDegree> applicationDegrees = []

static hasMany = [applicationDegrees: ApplicationDegree]
}

class ApplicationDegree {
Application app
Degree degree
Set applicationDegreeMajors = []

static hasMany = [applicationDegreeMajors: ApplicationDegreeMajor]
static belongsTo = [Application, Degree]
}

class ApplicationDegreeMajor {
ApplicationDegree applicationDegree
Major major

static belongsTo = [ApplicationDegree, Major]
}

如何创建别名,以便按专业分类?

Grails 3.1.4

最佳答案

我想可以在这里找到答案(和解决方法):https://forum.hibernate.org/viewtopic.php?t=947709

似乎不支持嵌套别名,因此我建议这样替换它们:

query.createAlias("applicationDegrees", "appDegrees");
query.createAlias("appDegrees.degree", "degree");
query.createAlias("appDegrees.applicationDegreeMajors", "appMajors");
query.createAlias("appMajors.major", "major");

关于sorting - Grails:多个嵌套关系的分离标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41645432/

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