我们有一个旧的应用程序,其关系定义如下:
class Practice {
String name
static hasmany = [doctors:Doctor]
}
和
class Doctor {
String name
}
belongsTo
中未定义Doctor
关系,因为我们不希望在删除Practice
时级联删除医生。这是一个非常古老的代码,不想更改它。
现在,根据新功能,用户在查看Practice
的详细信息时应该知道Doctor
与Doctor
相关联的{{1}}。任何人都可以帮助我知道在不更改域对象的情况下实现这一目标的最简单方法是什么?
答案 0 :(得分:7)
如果变量doctor
包含您要列出实践的医生,您可以通过发出以下标准查询获得医生关系中拥有此医生的Practice
个对象列表:
def practices = Practice.withCriteria {
doctors {
idEq(doctor.id)
}
}
答案 1 :(得分:0)
仅供记录
def practices = Practice.withCriteria {
doctors {
eq("id",doctor.id)
}
}