我有一个User类,其中有一个List字段,即pt。用户注册帐户时,不会初始化此字段。但是当用户执行此 Controller 操作时:
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()
}
但是通过脚手架使用用户/显示操作,我发现pt字段未保存在users对象上。我在哪里犯错?
最佳答案
您必须在Users域类中提供静态映射,以便Grails知道必须保留该字段:
class User {
static hasMany = [pt: String]
}
关于grails - 保存在我的域类对象上不起作用。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9051720/