gpt4 book ai didi

grails - Grails GORM搜索与另一个列表匹配的列表项

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

我有三个对象:

老师,
child ,
parent

Teacher.students是Child对象的列表

Parent.children也是Child对象的列表

我想找到所有教某位 parent 的 child 的老师。

我试过了,但只找到一个 child 的老师。如果 parent 有多个 child ,我需要这个。

def teachers = Teacher.withCriteria{ 
students {
inList("id", parent.children.first().id )
}
}

最佳答案

您只获取第一个ID。您需要使用所有 child 的ID,您可以使用点差(*)运算符获取。另外,根据docs,方法是in,而不是inList作为标准,但是我可能会遗漏有关版本的信息,等等:

in("id", parent.children*.id)

关于grails - Grails GORM搜索与另一个列表匹配的列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24101646/

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