I have a parent domain class the has a hasMany
of another domain class. Both the parent and the child domain classes have the lastUpdated
and the dateCreated
fields. My issue is that when I update a child domain class, I need the parent domain class to reflect that change and update its lastUpdated
field as well.
Is there any mapping or other configuration between the parent and child that Grails provides that would implement this feature?
Update
I added the following lines to the child domain class:
def beforeUpdate = {
parent.lastUpdated = new Date()
}
I also had to make sure in the controller that when I updated a child, I also had to save the parent as well to persist the new lastUpdated
field. This seems to work fine, but I would still like to know if there is a mapping or something similar that would do this.