Grails GORM,多层领域类的急切获取模式

4

我有以下的域名结构:

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 我原本希望通过将fetchMode设置为eager来始终加载特定对象。
我该如何更改我的域对象以确保像Survey.findById(1)这样的操作会加载所有问题和答案?
谢谢。
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接