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
,create
, 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 a Author
is deleted so will all his books.If the association doesn't define an owner (a "belong 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
domains associated with the Author
won't be deleted. If you wish to customize this behavior you can use the cascade
argument on an association:class Author {
static hasMany = [books:Book]
static mapping = {
books cascade:'all-delete-orphan'
}
}
Here a Book
will also be deleted if it is removed (orphaned) from the books
association.See the section on transitive persistence in the Hibernate user guide.