Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class User {
- String username
- String password
- String firstName
- String lastName
- String emailAddress
- UserStatus status
- UserType type
- Date dateCreated
- List<UserRole> roles
- static mapping = {
- roles(fetch: 'join')
- }
- }
- enum RoleType {
- SUPER_USER('superuser','Super User'),
- SUPPORT_USER('supportuser','Support User'),
- STANDARD('standard','Standard')
- String id
- String name
- RoleType(String id, String name) {
- this.id = id
- this.name = name
- }
- String toString() {
- name
- }
- }
- class UserRole {
- static belongsTo = [user:User]
- static auditable = true
- RoleType roleType
- String role
- static constraints = {
- role(nullable:false, blank:false)
- roleType(nullable:false, inList:RoleType.values().toList())
- }
- static mapping = {
- sort(role: "asc")
- role(role: IdentityEnumType,sqlType: "varchar(40)")
- }
- }
- User user = new User(
- username:'support@quirk.biz',
- password:'ilovequirk',
- status:UserStatus.ACTIVE,
- type:UserType.QUIRK,
- firstName:'Quirk',
- lastName:'Support',
- emailAddress:'support@quirk.biz'
- )
- UserRole userRole = new UserRole(roleType:RoleType.SUPER_USER, role:RoleType.SUPER_USER.toString())
- user.addToRoles(userRole)
- user.save(failOnError:true)
- No signature of method: za.co.hollard.User.addToRoles() is applicable for argument types: (za.co.hollard.UserRole) values: [za.co.hollard.UserRole : null]
- List<UserRole> roles
- static hasMany = [ roles:UserRole]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement