문제

I have two simple tables in my db

class A{
    String a_1
    String a_2
    static hasMany = [b:B]
}

class B{
    String b_1
    static belongsTo = [a:A]
}

and here is my controller

def getById = {
    def aInstance = A.get(1)
    render aInstance as JSON
}

and here is what i get

{"class":"com.A","id":1,"a_1":"a","a_2":"2","b":[{"class":"B","id":2},{"class":"B","id":1}]}

as per this documentation http://grails.org/doc/2.3.7/guide/GORM.html#oneToMany i thought i also will get b_1 parameter for my B class, but instead i just got ids

Is there any settings that i miss?

도움이 되었습니까?

해결책

did you try to fetch the b collection eagerly like this:

class A{
    String a_1
    String a_2
    static hasMany = [b:B]
    static fetchMode = [b: 'eager']
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top