Grails有许多关系查询

Grails有许多关系查询,grails,gorm,relationship,Grails,Gorm,Relationship,我有一种多对多的关系,但我不知道如何得到我需要的结果 Tutor { String name hasMany = [locations:Location] } Location { String name hasMany = [tutors:Tutor] belongsTo = Tutor } 数据库使用tutor、location和tutor_location(tutor.id、location.id)表看起来是正确的 如何找到与导师相关的所有位置 我

我有一种多对多的关系,但我不知道如何得到我需要的结果

Tutor {
    String name
    hasMany = [locations:Location]
}
Location {
    String name
    hasMany = [tutors:Tutor]
    belongsTo = Tutor
}
数据库使用tutor、location和tutor_location(tutor.id、location.id)表看起来是正确的

如何找到与导师相关的所有位置


我尝试过创建标准,但不起作用<代码>位置。listAllByTutor(tutorid)也不起作用。

首先找到您的
导师

def tutor = Tutor.get(1)
然后访问
位置

def locations = tutor.locations

这默认为延迟初始化,因此当您访问
位置
列表时,将执行第二个查询。

除非我遗漏了一些您在问题中没有说明的内容,但加载导师实例应使您能够访问该导师的位置集合。例如,myTutorInstance.Location我假设您在
之前有许多
属于
,是吗?