Change Log
v1.0
Breaking Changes
gorm.Openreturn type*gorm.DBinstead ofgorm.DBUpdating will only update changed fields
Most applications won't be affected, only when you are changing updating values in callbacks like
BeforeSave,BeforeUpdate, you should usescope.SetColumnthen, for example:func (user *User) BeforeUpdate(scope *gorm.Scope) { if pw, err := bcrypt.GenerateFromPassword(user.Password, 0); err == nil { scope.SetColumn("EncryptedPassword", pw) // user.EncryptedPassword = pw // doesn't work, won't including EncryptedPassword field when updating } }Soft delete's default querying scope will only check
deleted_at IS NULLBefore
db.Find(&user)will generate querying SQL if user hasDeletedAtfieldSELECT * FROM users WHERE deleted_at IS NULL OR deleted_at <= '0001-01-02'Now won't include blank time check
<= '0001-01-02anymore, will generat SQL like:SELECT * FROM users WHERE deleted_at IS NULLSo your application's
DeletedAtfield should not usetime.Timeas data type, need to use pointer*time.Timeor something likeNullTime. If you are usinggorm.Model, then you are good, nothing need to be change, just make sure all records using blank time fordeleted_athas been set to NULL, sample migration script:import ( "github.com/jinzhu/now" ) func main() { var models = []interface{}{&User{}, &Image{}} for _, model := range models { db.Unscoped().Model(model).Where("deleted_at < ?", now.MustParse("0001-01-02")).Update("deleted_at", gorm.Expr("NULL")) } }New ToDBName logic
Before when GORM convert Struct, Field's name to db name, only those common initialisms from golint like
HTTP,URIare special handled.So field
HTTP's db name will behttpnoth_t_t_p, but some other initialisms likeSKUthat not in golint, it's db name will bes_k_u, this release fixed this, any upper case initialisms should be converted correctly.If your applications using some upper case initialisms which doesn't exist in golint, you need to overwrite generated column name with tag, like
sql:"column:s_k_u", or alert your database's column name according to new logic