Grails domain obj action argument and association data binding

Viewed 272

I know Grails v2.3 introduced some changes to the way data binding works, but I'm struggling to figure out how to get automatic association binding to work when I have an domain obj as the action argument. For instance, with a couple of simple domain objects:

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

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

and controller action:

def doSomething(Author a) {
    // only simple properties appear to be bound at this point
}

if the incoming param obj is [id:4, name:Stephen King], the Author obj with ID 4 will be loaded and the name set to 'Stephen King'. If, however, I try to set one book reference, generating a param obj that looks like this: [id:4, name:Stephen King, books[0].id:21, books[0]:[id:21]], only the name change is bound; the books association remains unchanged. (It's also worth noting that a.hasErrors() == false as well.)

If, however, I adjust the controller action to be like this:

def doSomething(Author a) {
    a.properties = params
    // now the books association is bound
}

the data binding works as expected...but that kind of defeats the purpose of using an action argument.

What am I doing wrong?

0 Answers
Related