I am trying to tweak the Date lastUpdated property in my domain class so that it only changes when one of the fields(lastName) is updated. Cant seem to get it to work...My code is below..Please i need help
package com.bt.helloworld
class Person {
String firstName
String lastName
Date lastUpdated
Date dateCreated
static mapping ={
//autoTimestamp false
}
static constraints = {
lastUpdated(nullable:true)
dateCreated(nullable:true)
}
def beforeUpdate = {
Person currentPerson = new Person()
//currentPerson = Person.findById(this.id)
if (!currentPerson.lastName.equals(this.lastName)) {
lastUpdated = new Date()
}
if(!currentPerson.firstName.equals(this.firstName)){
lastUpdated = null
}
}
//def onLoad = {
//firstName = this.firstName
//lastName = this.lastName
//}
//String toString() {"${this.firstName} : ${this.lastName} : ${this.lastUpdated}} "}
}
package com.bt.helloworld
class Person {
String firstName
String lastName
Date lastUpdated
Date dateCreated
static mapping ={
//autoTimestamp false
}
static constraints = {
lastUpdated(nullable:true)
dateCreated(nullable:true)
}
def beforeUpdate = {
Person currentPerson = new Person()
//currentPerson = Person.findById(this.id)
if (!currentPerson.lastName.equals(this.lastName)) {
lastUpdated = new Date()
}
if(!currentPerson.firstName.equals(this.firstName)){
lastUpdated = null
}
}
//def onLoad = {
//firstName = this.firstName
//lastName = this.lastName
//}
//String toString() {"${this.firstName} : ${this.lastName} : ${this.lastUpdated}} "}
}