"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Database Mapping/cascade.html" (14 Sep 2022, 62198 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)

cascade

Purpose

Configures the cascading behavior of an association.

Examples

class Author {

    static hasMany = [books: Book]

    static mapping = {
        books cascade: 'all-delete-orphan'
    }
}

Description

Usage: association_name(cascade:string)

Arguments:

  • cascade - The cascading behavior to define. Can be one or more (comma-separated) of all, merge, save-update, delete, lock, refresh, evict, replicate or all-delete-orphan (one-to-many associations only).

By default GORM configures a cascading policy of "all" in the case where one entity "belongs to" another. For example:

class Book {
    static belongsTo = [author: Author]
}
class Author {
    static hasMany = [books: Book]
}

Here all persistence operations will cascade from the Author domain to the Book domain. So when an Author is deleted so will all the associated books.

If the association doesn’t define an owner (a "belongs to" relationship):

class Book {
}
class Author {
    static hasMany = [books: Book]
}

then GORM uses a cascading policy of "save-update" by default. So if an Author is deleted the Book associated domains won’t be deleted. Use the cascade argument on an association to customize this behavior:

class Author {

    static hasMany = [books: Book]

    static mapping = {
        books cascade: 'all-delete-orphan'
    }
}

Using this configuration a Book will also be deleted if it is removed (orphaned) from an Author’s `books association.

See the section on transitive persistence in the Hibernate user guide.