GORM 不忽略带有 `gorm:"-"` 的字段
GORM Not ignoring field with `gorm:"-"`
使用 Jinzhu 的 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
}
但我也使用 Gorilla 的 Schema
包,因此任何形式的值都会填充结构,但我不希望将 PasswordC
保存到数据库中,因为它将是纯文本正常的 Password
字段得到 bcrypt' 所以关于如何使 GORM
不保存 PasswordC
字段的任何信息。
使用 Jinzhu 的 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
}
但我也使用 Gorilla 的 Schema
包,因此任何形式的值都会填充结构,但我不希望将 PasswordC
保存到数据库中,因为它将是纯文本正常的 Password
字段得到 bcrypt' 所以关于如何使 GORM
不保存 PasswordC
字段的任何信息。