Created
October 3, 2012 17:09
-
-
Save iocopocomaioco/3828362 to your computer and use it in GitHub Desktop.
Standard GORM domain class in Grails
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
package 'packageName' | |
import 'whateverPackagesYouNeed' | |
// note: a GORM class can extend another - default behaviour is: they will be on same table | |
class User extends SecUser{ | |
// on IDs - you must either set yorseld - or choose generation method | |
String userId | |
Date dateCreated = new Date() | |
Company company | |
// a user can have multiple projects and assignments | |
static hasMany = [assignments:Assignment, companies:Projects] | |
// direction of ownership - relationship declared (Company has many users) | |
static belongsTo = [Company] | |
// declares a 1:1 relationship with Profile class | |
Profile profile | |
// define validation constraints for properties | |
static constraints = { | |
profile(nullable:true, unique:true) | |
userId (nullable:false, unique:true) | |
company (nullable:false) | |
} | |
// declare unique ID generation method | |
static mapping = { | |
userId column: '`userId`' | |
userId generator: 'uuid' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment