Is it possible to override List accessors in Grails domain classes?
Posted
by Ali G
on Stack Overflow
See other posts from Stack Overflow
or by Ali G
Published on 2010-03-25T15:49:55Z
Indexed on
2010/03/25
15:53 UTC
Read the original article
Hit count: 477
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 = {
}
}
© Stack Overflow or respective owner