How to initialize a Date field in a Grails domain object to act as a timestamp?

I have a domain class that has two dates in it, and I want one of them to be filled with the current time the record was created for the object, for example, create a timestamp ...

class Contact {
    Date initiatedDate
    Date acceptedDate
}

Is it only enough for a new object Dateon one of them to make the other valid until it fills it, sort of ...

class Contact {

    static constraints = 
    {
        acceptedDate(nullable:true)
    }

    Date initiatedDate = new Date()
    Date acceptedDate
}

I am experimenting, but I would like to know if this is right for this, or is there something more Grailsy or GORMy that I have to do, say, in a function initor by setting a domain, defining a default object, for example, idand version.

thanks

+5
1

, , , GORM -timestamping, :

class Contact {
    Date dateCreated
}

grails, , GORM .

+9

All Articles