(Quick Reference)

belongsTo

The belongsTo declaration controls the behavior of cascaded deleted and automatically set back references when objects are added to hasMany relationships. More specifically:

  • It results in a cascading delete when the parent object is deleted with the cascade: true option specified.
  • It results in the property being set automatically when the object is added to a hasMany relationship of the owning class

For example, give the classes:

class Book {
    String title
    Author author
    static belongsTo = [author: Author]
}

and:

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

Adding a Book object to an Author object will automatically set the author back-pointer in the book object:

author.addToBooks(new Book("The Grapes of Wrath"))

and deleting an author object with the cascade: true option set will automatically delete all of its books:

author.delete(cascade: true)

Note that, unlike with GORM, cassandra-orm plugin only cascades saves and deletes when the option is specified.