(Quick Reference)

save

Purpose

Saves the domain class instance

Examples

def b = new Book(title:"The Shining")
b.save()

Description

The save method returns null if validation failed and the instance was not saved and the instance itself if successful. This allows you to write code like the following:

if( !b.save() ) {
   b.errors.each {
        println it
   }
}

Parameters:

  • validate - If set to false no constraint validation will occurr. Default: true
  • failOnError - If set to true an exception with validation errors will be thrown. Default: false