Grails GORM搜索与另一个列表匹配的列表项
我有三个目标: 老师,, 小孩 母公司 Teacher.students是子对象的列表 Parent.children也是子对象的列表 我想找到所有教某位家长孩子的老师Grails GORM搜索与另一个列表匹配的列表项,grails,groovy,gorm,Grails,Groovy,Gorm,我有三个目标: 老师,, 小孩 母公司 Teacher.students是子对象的列表 Parent.children也是子对象的列表 我想找到所有教某位家长孩子的老师 def teachers = Teacher.withCriteria{ students { inList("id", parent.children.first().id ) } } 我试过了,但只找到了一个孩子的老师。如果父母有多个孩子,我需要这样做 def teachers =
def teachers = Teacher.withCriteria{
students {
inList("id", parent.children.first().id )
}
}
我试过了,但只找到了一个孩子的老师。如果父母有多个孩子,我需要这样做
def teachers = Teacher.withCriteria{
students {
inList("id", parent.children.first().id )
}
}
您仅获取第一个id;您需要使用所有孩子的id,您可以使用spread(
*
)操作符获得这些id。此外,根据,方法是中的,而不是标准的列表中的,但我可能遗漏了版本的某些内容,等等:
in("id", parent.children*.id)