Last active
August 29, 2015 14:19
-
-
Save aadrian/d0b2ff0e29c23ae2831f to your computer and use it in GitHub Desktop.
Grails "Created By" and "Last Updated By" Fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// domain | |
class MyDomainEntity { | |
transient springSecurityService | |
// usual fields ... | |
String name | |
// ... | |
Date dateCreated | |
Date lastUpdated | |
String createdBy | |
String lastUpdatedBy | |
static transients = ['springSecurityService'] | |
static constraints = { | |
// ... usual fields | |
dateCreated nullable: true | |
lastUpdated nullable: true | |
createdBy nullable: true | |
lastUpdatedBy nullable: true | |
} | |
String toString() { name } | |
def beforeInsert(){ createdBy = springSecurityService.getPrincipal()?.getUsername() } | |
def beforeUpdate(){ lastUpdatedBy = springSecurityService.getPrincipal()?.getUsername() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment