我有以下的域名结构:
class Survey {
Integer id
String title
static hasMany = [questions: Question]
static constraints = {
id()
title()
questions()
}
String toString(){
return title
}
}
class Question {
Integer id
String text
static hasMany = [responses: Response]
static fetchMode = [responses: 'eager']
static constraints = {
id()
text()
responses()
}
String toString(){
return text
}
}
class Response {
Integer id
String text
Integer numberOfPeopleSelected = 0
static constraints = {
id()
text()
numberOfPeopleSelected()
}
String toString(){
return text
}
}
我已经修改了
Bootstrap.groovy
文件以在启动时初始化一些数据,并分别调用Survey.list()
、Question.list()
和Response.list()
来显示每个单独级别创建的期望值。然而,当我执行
Survey.list()
并进入问题时,响应总是为空,如下图所示:
![enter image description here](https://istack.dev59.com/AzXdm.webp)
我该如何更改我的域对象以确保像
Survey.findById(1)
这样的操作会加载所有问题和答案?谢谢。