使用金珠的GORM包装这太棒了顺便说一句,我现在有这样的结构:GORM没有忽视场`GORM:“ - ”'
type User struct {
gorm.Model
// The Users username
Username string `gorm:"size:255;unique;not null"`
// The Users email address
Email string `gorm:"size:255;unique;not null"`
// The Users hashed password
Password string `gorm:"size:255;not null"`
// The Users password confirmation (only for forms)
PasswordC string `gorm:"-"`
// The Users FULL NAME (e.g. Burt Reynolds)
Fullname string `gorm:"size:255; not null"`
// The Users Karma level
Karma int
// Is the user banned?
Banned bool
}
但我也用大猩猩的Schema
包,因此任何形式的值填充结构,但我不希望PasswordC
保存到数据库中,因为它将是纯文本的,因为正常的Password
字段被加密,因此有关如何使GORM
不保存PasswordC
字段的任何信息。
gorm docs表明这是忽略字段的正确语法:http://jinzhu.me/gorm/models.html#model-definition--你看到了吗? – elithrar
尝试通过替换它,PasswordC字符串'sql:“ - ”' – qwertmax