When the bool field value is false, gorm doesnt update using .Select(fieldName). Works with Save though.
go version)?1.10rc2
PostgreSQL 10.3
db.DBManager().Select("BoolField").Model(model).Updates(model)
Model:
package models
type Commodity struct {
BaseModel
BoolField bool `gorm:"column:bool_field;type:boolean;default:false" valid:"-" json:"bool_field" form:"bool_field" query:"-"`
}
I am not sure whether to solve your problem.
in mysql.
Type Test struct{
SomeField uint
}
i use the Model(&Test{}).Select("some_field").xxxxx
the gorm will generate the database's column some_field.
confirm your column's real name.and make sure the Model before theSelect.
@dongshimou Can you confirm that it works for you in latest release version?
yes. see the doc
if you use the struct update . make sure the update column is not default value.
for example : v:=Test{}. default value: v.SomeField == 0, if you wan't update to 0,
Model(&Test{}).Update(&v). the some_field column will not be update.
it will be failure.
BoolField bool
The field type is bool. And i can't set it to false because false is a default value for bool.
And bool field cant be set to false with Model(&Test{}).Select("bool_field")
use the map[string]interface{} to update. :)
@dongshimou
I know that its possible to do with map[string]interface{} or .Save().
Ive opened this issue because it should be possible to do with Select() and Update() as well.
https://github.com/jinzhu/gorm/issues/469#issuecomment-95776852
set the field to *bool?
@ik9999 did you find a solution?
@penguinpowernz No, i stopped using gorm and use query builders + sqlx instead.
@ik9999 thanks for replying
Most helpful comment
@penguinpowernz No, i stopped using gorm and use query builders + sqlx instead.