BeforeUpdate afterUpdate

We have beforeUpdateOf * (where * is some field?)

and one more question:

def beforeUpdate = {log.info ("in beforeUpdate" + this.status)}

def afterUpdate = {log.info ("in afterUpdate" + this.status)}

This gives the same status. Although the actual state of the object (this) is updated from x to y

+3


source to share


2 answers


There is no event when the property changes, but you can add an explicit setter that does something:

class MyDomainClass {
   String status

   void setStatus(String status) {
      this.status = status
      // do something based on changed value
   }
}

      



You see the same value in beforeUpdate

and afterUpdate

, because these callbacks are for Hibernate persisting the changed values ​​to the database. It would be unusual for the value to change between the time Hibernate was started and the update completed.

If you are looking for the original value from the database, it is available at http://grails.org/doc/latest/ref/Domain%20Classes/getPersistentValue.html

+3


source


You might want to take a look at the Grails audit plugins: Audit Log and Trail Audit



0


source







All Articles