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)Usage:
association_name(fetch:string)引数: Arguments:
fetchStrategy- The fetching strategy to use. Eitherjoinorselect.
SELECT when the association is accessed. If you prefer that the association be fetched eagerly at the same time then you can override the behavior:class Author { static hasMany = [books: Book] static mapping = {
books fetch: 'join'
}
}books association will be fetched using a join at the same time the author is retrieved, for example:def author = Author.get(1) // the books collection is pre-initialized - no risk of lazy loading exceptions

