Grails’ dateCreated and lastUpdated properties
I’m in the process of learning Groovy and Grails, and Grails has this neat feature called scaffolding where you just create a domain class like a User and all its properties, and it’s auto-create a full CRUD to be able to create/read/update/and delete.
class User { String userId String password Date dateCreated Date coolStuff Profile profile }
Which when creating, will generate a form like this:
But I was wondering what’s the deal with dateCreated. Turns out that if you define dateCreated and lastUpdated properties, Grails will automatically take care of storing in the database the record creation date and when it was last updated (which is all facilitated via Grails’ ORM Hibernate wrapper).
Grails is magic. It is one of the few frameworks that does what you want by default, taking care of the tedious boilerplate that we are all so used to wasting our time writing and maintaining. GORM, in particular, makes data access fun again, letting you focus on the business value, rather than trying to bend the code to your will.