gpt4 book ai didi

GORM 不忽略 `gorm:"-"` 字段

转载 作者:IT王子 更新时间:2023-10-29 01:11:23 30 4
gpt4 key购买 nike

使用 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'd 所以关于如何使 GORM 不保存 PasswordC 字段的任何信息。

最佳答案

docsgorm:"-",但是 code表示 sql:"-" 是正确的语法。

我的测试证实了这一点。

关于GORM 不忽略 `gorm:"-"` 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36963008/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com