"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Database Mapping/fetch.html" (14 Sep 2022, 60571 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(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 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.