私は次のドメイン構造を持っています:
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()
質問を掘り下げると、次のように、応答は常に null になります。
fetchModeを熱心に設定することで、常にその特定のオブジェクトをロードする必要があると予想していました。
ドメイン オブジェクトで何を変更すれば、そのようなことを行ったときにSurvey.findById(1)
すべての質問と回答が確実に読み込まれるようになりますか?
ありがとう