////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

As described in the section on <<cascades,cascading updates>>, the primary mechanism to control the way updates and deletes cascade from one association to another is the static <<ref-domain-classes-belongsTo,belongsTo>> property.

However, the ORM DSL gives you complete access to Hibernate's https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#associations[transitive persistence] capabilities using the `cascade` attribute.

Valid settings for the cascade attribute include:

* `merge` - merges the state of a detached association
* `save-update` - cascades only saves and updates to an association
* `delete` - cascades only deletes to an association
* `lock` - useful if a pessimistic lock should be cascaded to its associations
* `refresh` - cascades refreshes to an association
* `evict` - cascades evictions (equivalent to `discard()` in GORM) to associations if set
* `all` - cascade _all_ operations to associations
* `all-delete-orphan` - Applies only to one-to-many associations and indicates that when a child is removed from an association then it should be automatically deleted. Children are also deleted when the parent is.


To specify the cascade attribute simply define one or more (comma-separated) of the aforementioned settings as its value:

[source,java]
----
class Person {

    String firstName

    static hasMany = [addresses: Address]

    static mapping = {
        addresses cascade: "all-delete-orphan"
    }
}
----

[source,java]
----
class Address {
    String street
    String postCode
}
----
