i've confused by lazy initialized collections in a bidirectional one-to-many relation,
i've two domains Module and Rule, there is a bidirectional otm between them
Class Module{
..
static hasMany = [providedRules : Rule]
..
}
Class Rule{
..
static belongsTo = [module : Module]
..
}
a simple method for testing:
def module = Module.get(id)
module.providedRules.each{
println it.description // i expected a query to Rule table for each iteration
}
i would expect a query for each access to "description" property, but i didn't see any queries for iterations.
have you any ideas ?
thanks
Add logging like this and see what happens in logs:
datasource {
...
logSql = true
...
}
See also fetching in docs Update: Checked in grails. Remove belongsTo from Rule and it works like you want. Lokks like if bidirectional mapping, it loads not a proxy but full object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.