Skip to content

Instantly share code, notes, and snippets.

@iocopocomaioco
Created October 3, 2012 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iocopocomaioco/3828362 to your computer and use it in GitHub Desktop.
Save iocopocomaioco/3828362 to your computer and use it in GitHub Desktop.
Standard GORM domain class in Grails
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