<commit_before>It is critical that you understand how cascading updates and deletes work when using GORM. The key part to remember is the `belongsTo` setting which controls which class "owns" a relationship.

Whether it is a one-to-one, one-to-many or many-to-many, defining `belongsTo` will result in updates cascading from the owning class to its dependant (the other side of the relationship), and for many-/one-to-one and one-to-many relationships deletes will also cascade.

If you _do not_ define `belongsTo` then no cascades will happen and you will have to manually save each object (except in the case of the one-to-many, in which case saves will cascade automatically if a new instance is in a `hasMany` collection).

Here is an example:

[source,groovy]
----
class Airport {
    String name
    static hasMany = [flights: Flight]
}
----

[source,groovy]
----
class Flight {
    String number
    static belongsTo = [airport: Airport]
}
----

If I now create an `Airport` and add some `Flight`s to it I can save the `Airport` and have the updates cascaded down to each flight, hence saving the whole object graph:

[source,groovy]<commit_msg>Asciidoc formatting tweak for inline code<commit_after>It is critical that you understand how cascading updates and deletes work when using GORM. The key part to remember is the `belongsTo` setting which controls which class "owns" a relationship.

Whether it is a one-to-one, one-to-many or many-to-many, defining `belongsTo` will result in updates cascading from the owning class to its dependant (the other side of the relationship), and for many-/one-to-one and one-to-many relationships deletes will also cascade.

If you _do not_ define `belongsTo` then no cascades will happen and you will have to manually save each object (except in the case of the one-to-many, in which case saves will cascade automatically if a new instance is in a `hasMany` collection).

Here is an example:

[source,groovy]
----
class Airport {
    String name
    static hasMany = [flights: Flight]
}
----

[source,groovy]
----
class Flight {
    String number
    static belongsTo = [airport: Airport]
}
----

If I now create an `Airport` and add some ``Flight``s to it I can save the `Airport` and have the updates cascaded down to each flight, hence saving the whole object graph:

[source,groovy]
{'fraction_non_alphanumeric': 0.07369323050556983, 'fraction_numerical': 0.0, 'mean_word_length': 3.9470338983050848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7655792', 'n_tokens_mistral': 673, 'n_tokens_neox': 643, 'n_words': 338}