I have a transient method inside of my domain class that will update a property of the class. When I use this method the class is not marked as dirty and does not save.
class Major {
String code
String major
static transients = ['update']
def update(String newVal) {
major = newVal
}
}
Major major = Major.findByCode("ACAA");
major.update("NEW VALUE");
println("Is dirty? "+ major.dirty); //Is dirty? false
When I update the property outside the method it works as expected and I can save
Major major = Major.findByCode("ACAA");
major.major = "NEW VALUE";
println("Is dirty? "+ major.dirty); //Is dirty? true
Is there a reason this does not work?
Grails 3.3.1
GORM 6.1.6
The error lies in the update function. It needs to explicitly call the setter like this:
def update(String newVal) {
setMajor(newVal)
}
For reference, see the GORM upgrade notes for the new dirty checking implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With