4
我有以下结构域结构域类的多个层:Grails的GORM,渴望取模式
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()
并钻入问题时,回答总是空,像这样创建:
我在期待通过设置fetchMode渴望它应该总是加载该特定的对象。
我可以在我的域对象上更改什么,以确保当我执行类似Survey.findById(1)
的操作时,它会加载所有问题和响应?
感谢