Ant's
Ant's

Reputation: 13811

Save On My Domain Class Object Is Not Working.

I have a User class which has a List field namely pt. This field is not initialized when User register his account. But when user goes this controller action :

def updatePt() { 
       //performs some action 
       def user = User.get(springSecurityService.principal.id)  //find the user 
       user.pt = [] 
       //on certain conditions i put values into user.pt like this 
       user.pt << "E" 
       //at last I save it 
       user.save() 
} 

But using user/show action via scaffolding I found that pt field is not saved on users object. Where I'm making a mistake?

Upvotes: 1

Views: 1208

Answers (2)

Kai Sternad
Kai Sternad

Reputation: 22850

You have to provide a static mapping in the Users domain class so that Grails knows the field must be persisted:

class User {
    static hasMany = [pt: String]
}

Upvotes: 1

Igor Artamonov
Igor Artamonov

Reputation: 35951

It's possible because of validation error. Try with

if (!user.save()) {
   log.error('User not saved')
   user.errors.each {
       log.error('User error: $it')
   }
}

PS or you can use println instead of log.error

Upvotes: 1

Related Questions