I am trying to use a common beforeUpdate
method by writing in BootStrap.groovy
.
def init = { servletContext ->
for (domainClass in grailsApplication.domainClasses) {
if(domainClass.clazz.simpleName == domainName){
domainClass.metaClass.beforeUpdate = {
println "i am here "
def dirtyPropertyNames = this.getDirtyPropertyNames()
println(dirtyPropertyNames)
if(dirtyPropertyNames != null && dirtyPropertyNames.size() > 0) {
for (dirtyPropertyName in dirtyPropertyNames) {
def oldValue = (this.getPersistentValue((dirtyPropertyName)))
def newValue = (this."${dirtyPropertyName}")
}
}
}
}
}
}
But I cannot use this.getdirtyPropertyNames()
as it gives an error.
groovy.lang.MissingMethodException: No signature of method:
If it's in the domain itself, this.getDirtyPropertyNames()
works fine.
I tried using domainClass.getDirtyPropertyNames()
too but it still gives an error.
I am using Grails 4.