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)
的操作時,它會加載所有問題和響應?
感謝