(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)
使用方法:
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 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' } }

Here the 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

Note that excessive use of joins can be a performance bottleneck. See the section on Eager vs Lazing Fetching in the user guide.