I've turned on the logger to see the values and I'm noticing that when I update a boolean to false that it doesn't get updated in the database.
When boolean is true
DB.Model(&item).UpdateColumns(Item{
Name: "demo",
Display: true,
})
UPDATE "items" SET "display" = 'true', "name" = 'demo' WHERE ("id" = '1')
When boolean is false
DB.Model(&item).UpdateColumns(Item{
Name: "demo",
Display: false,
})
UPDATE "items" SET "name" = 'demo' WHERE ("id" = '1')
gorm will ignore zero-values when update struct. and this is what we can't fix ;( (because golang will always initialize all values, so when update with struct, gorm can't know it is setted by you or initialized by golang)
But you could update the value in a different way:
// solution 1
DB.Model(&page).Update("CommentsEnabled", commentsenabled)
// solution 2
page.Commentsenabled = commentsenabled;
DB.Save(&page)
// solution 3
DB.Model(&page).Updates(map[string]interface{}{"CommentsEnabled": commentsenabled})
///
First i got this error too.
When i update gorm by git yesterday, this bug is fixed
When display is false, it make the sql like this
UPDATE "items" SET "display" = 'false', "name" = 'demo' WHERE ("id" = '1')
However, it works in mysql, the display is set to 0.
Most helpful comment
gorm will ignore zero-values when update struct. and this is what we can't fix ;( (because golang will always initialize all values, so when update with struct, gorm can't know it is setted by you or initialized by golang)
But you could update the value in a different way: