使用金柱的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字段被加密的纯文本,所以任何关于如何使GORM不保存PasswordC字段的信息都会被保存。
发布于 2016-05-02 10:09:34
docs显示为gorm:"-",但code表示sql:"-"是正确的语法。
我的测试验证了这一点。
https://stackoverflow.com/questions/36963008
复制相似问题