Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

beforeUpdate afterUpdate

do we have beforeUpdateOf* (where * is some field?)

and another question :

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

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

This both gives same status. Although actually status of object(this) is updated from x to y

like image 949
nandini Avatar asked Dec 01 '25 06:12

nandini


1 Answers

There's no event for when a property is changed, but you could add in an explicit setter that does something:

class MyDomainClass {
   String status

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

You're seeing the same value in beforeUpdate and afterUpdate because those callbacks are for when Hibernate saves the changed values to the database. It would be unusual for the value to change between the time that Hibernate starts and finishes the update.

If you're looking for the original value from the database, it's available using http://grails.org/doc/latest/ref/Domain%20Classes/getPersistentValue.html

like image 133
Burt Beckwith Avatar answered Dec 03 '25 23:12

Burt Beckwith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!