Your Question
The time field cannot be set to null if it already has a value
a go struct:
type Test struct {
gorm.Model
Date null.Time // gopkg.in/guregu/null.v3 and I have tested sql.NullTime zero.Time null.Time *time.Time
}
a gin route use to update Test
r := gin.Default()
r.GET("/update", func(c *gin.Context) {
var body Test
if err := c.BindJSON(&body); err != nil {
c.String(http.StatusOK, "err")
return
}
// db, _ := gorm.Open("")
db.Model(&Test{}).Where("id = ?", body.ID).Update(body)
c.String(http.StatusOK, "ok")
})
r.Run()
post data:
{
"id": 1,
"Date": null // or has other method?
}
Is there any way to set the time field to null? I have some restrictions, so can't use
gorm.Expr("null"), This happens in a web framework based on gorm + gin
The document you expected this should be explained
Expected answer
Comment From: a631807682
NOTE When updating with struct, GORM will only update non-zero fields. You might want to use map to update attributes or use Select to specify fields to update
https://gorm.io/docs/update.html#Update-Selected-Fields