当我们用另一个结构包装时,Gorm golang sql.NullInt64 不起作用
Gorm golang sql.NullInt64 not working when we wrapper with another struct
用户可以被其他用户删除。那样的话,
type User struct {
gorm.Model
Email string `gorm:"type:varchar(100)"`
DeletedBy sql.NullInt64
}
创建新用户时DeletedBy为空。所以我使用 sql.NullInt64 而不是 int64。
但我无法转换为 JSON。
{ "Email": "xxxxx",
"DeletedBy":
{"Int64":2,"Valid":true}
}
为此,我尝试了 https://gist.github.com/smagch/bc34f861df65c8ea2e90
但是 Gorm 将查询条件值发送为 "[{2, true}]"
用户可以被其他用户删除。那样的话,
type User struct {
gorm.Model
Email string `gorm:"type:varchar(100)"`
DeletedBy sql.NullInt64
}
创建新用户时DeletedBy为空。所以我使用 sql.NullInt64 而不是 int64。 但我无法转换为 JSON。
{ "Email": "xxxxx", "DeletedBy": {"Int64":2,"Valid":true} }
为此,我尝试了 https://gist.github.com/smagch/bc34f861df65c8ea2e90 但是 Gorm 将查询条件值发送为 "[{2, true}]"