(Quick Reference)
addTo*
Purpose
Adds a domain class relationship for one-to-many or many-to-many relationship, where the relationship is indicated by the property used as the suffix to the method.
Examples
def fictBook = new Book(title:"IT")
def nonFictBook = new Book(title:"On Writing: A Memoir of the Craft")
def a = new Author(name:"Stephen King")
.addToFiction(fictBook) // 'fiction' is name of relationship property
.addToNonFiction(nonFictBook) // 'nonFiction' is name of relationship property
.save()
Description
The
addTo*
method is a dynamic method that uses an association to automatically add instances to the association.
The method expects an instance of the associated class:
def fictBook = new Book(title:"IT")
def nonFictBook = new Book(title:"On Writing: A Memoir of the Craft")
def a = new Author(name:"Stephen King")
.addToFiction(fictBook) // 'fiction' is name of relationship property
.addToNonFiction(nonFictBook) // 'nonFiction' is name of relationship property
.save()