开发者

Grails automatic relational fetching

开发者 https://www.devze.com 2023-02-05 02:56 出处:网络
Is is possible to do automatic rel开发者_JAVA技巧ation fetching in GORM / Grails? class Person { static hasMany = [cars : Car]

Is is possible to do automatic rel开发者_JAVA技巧ation fetching in GORM / Grails?

class Person {
    static hasMany = [cars : Car]
}
class Car {
    static belongsTo = [owner : Person]
}

Then use this relation like:

person = Person.get(1);
person.cars.each() { print it; }


You can enable eager fetching this way:

static mapping = {
   cars fetch: 'join'
}

See http://grails.org/doc/latest/ref/Database%20Mapping/fetch.html


The answer is: Yes, that works.

But I recommend reading the GORM Gotchas, to fully understand the basics of Hibernate under Grails' hood. Or sometimes you will see "surprisingly" behavior.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号