(Quick Reference)
fetch
Purpose
Configures the fetching behavior of an association.
Examples
class Author {
static hasMany = [books:Book]
static mapping = {
books fetch:'join'
}
}
Description
Usage:
association_name(fetch:string)
Arguments:
fetchStrategy
- The fetching strategy to use. Either join
or select
.
By default GORM assumes fetching of associations is done using a
SELECT
when the association is accessed. If you prefer the association is fetched eagerly at the same time as object then you can override the fetch behavior:
class Author {
static hasMany = [books:Book]
static mapping = {
books fetch:'join'
}
}
Here the
books
association will be fetching using a join at the same time a particular author is looked up such as:
def author = Author.get(1)
Note that excessive use joins can be a performance bottleneck. See the section on
Eager vs Lazing Fetching in the user guide.