I am trying to understand how Grails 2.3.4 generated scaffolding methods perform validation. For instance this is what was generated for my Club domain save method:
def save(Club clubInstance) {
if (clubInstance == null) {
notFound()
return
}
if (clubInstance.hasErrors()) {
respond clubInstance.errors, view:'create'
return
}
clubInstance.save flush:true
request.withFormat {
form {
flash.message = message(code: 'default.created.message', args: [message(code: 'clubInstance.label', default: 'Club'), clubInstance.id])
redirect clubInstance
}
'*' { respond clubInstance, [status: CREATED] }
}
}
From what I understand the first phase of validation happened upon the data binding to the Club clubinstance parameter of the save action. So any data binding errors will be caught on the if (clubInstance.hasErrors()).
I see no explicit call to clubInstance.validate() or any error check on clubInstance.save as the documentation suggests. It does seem to work however. So how does this method validate and return back to the view if there are constraint violations?
More importantly should we not be using the generated scaffolding controllers as the best practice way to do basic CRUD in Grails?