[Golang] gorm update data update is ignored when the solution value is 0

When updating with a struct, by default, GORM will only update fields with non-zero values.
Ignored when update has a value of 0
Structure cannot be used
The Updates method supports struct and map[string]interface{} parameters.

// Update properties based on map
db.Model(&user).Updates(map[string]interface{}{“name”: “hello”, “age”: 18, “active”: false})

To use the map data type
For example, change it to this

values := map[string]uint{
"Status": status,
}
DB.Model(&User{}).Where(query, args…).Update(values)

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish