This question looks somewhat similar, but the asker there was attempting to understand how a one-to-many data binding works when the Domain object is a Controller action argument.
I want to understand, under-the-hood, what methods are being invoked when the Domain class is provided as an argument to a Controller action. Consider the default update action:
def update(MyDomain myDomain) {
if (myDomain == null) {
notFound()
return
}
try {
myDomainService.save(myDomain)
} catch (ValidationException e) {
respond myDomain.errors, view:'edit'
return
}
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.updated.message', args:
[message(code: 'myDomain.label', default: 'MyDomain'), myDomain.id])
redirect myDomain
}
'*'{ respond myDomain, [status: OK] }
}
}
What is the sequence of events leading up to the scope of the above Controller action? My best guess is below, but I would like confirmation.
def someActionWrapper() {
MyDomain instance = MyDomain.get(params.id)
instance.properties = params
update(instance)
}
I think it must be going to the DB to pick up any fields that weren't on the form, then overwriting with any values that were on the form, then calling the actual controller action.
Edit
Current versions of libraries when this question was asked:
- Grails 3.3.1
- Groovy 2.4.12