If I have a List in a Grails domain class, is there a way to override the addX() and removeX() accessors to it?
In the following example, I'd expect MyObject.addThing(String) to be called twice. In fact, the output is:
Adding thing: thing 2
class MyObject {
static hasMany = [things: String]
List things = []
void addThing(String newThing) {
println "Adding thing: ${newThing}"
things << newThing
}
}
class BootStrap {
def init = { servletContext ->
MyObject o = new MyObject().save()
o.things << 'thing 1'
o.addThing('thing 2')
}
def destroy = {
}
}