withCriteria two level deep association eager fetch grails

后端 未结 1 1427
迷失自我
迷失自我 2021-02-05 14:13


I\'d like to eager load a structure, two levels deep in an association chain. Something along the lines of:

class TopLevel {
    String name

    LevelOne l         


        
1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 14:54

    Got it working. Here's the secret sauce:

    def result = TopLevel.withCriteria {
        eq('name', 'test')
        fetchMode 'levelOne', FetchMode.JOIN
        fetchMode 'levelOne.levelTwo', FetchMode.JOIN
        fetchMode 'levelOne.levelTwo.levelThree', FetchMode.JOIN
    }
    

    0 讨论(0)
提交回复
热议问题