These are chat archives for jinzhu/gorm

28th
Jun 2016
Sarath Sadasivan Pillai
@sarathsp06
Jun 28 2016 06:33
Call backs can solve this pretty well. I changed the type of my datetime to a custome type and called it MysqlTime as the mysql needed formating for datetime different from the default time.Time formating .Here is how i did the callback work
//registering call back to be used to set created at for create requests
    gorm.DefaultCallback.Update().Remove("gorm:update_time_stamp")
    gorm.DefaultCallback.Update().Register("gorm:update_time_stamp", func(scope *gorm.Scope) {
        if !scope.HasError() {
            now := func() MySQLDateTime {
                return *(NewMySQLDateTime(time.Now()))
            }
            scope.SetColumn("UpdatedAt", now())
        }
    })
This is called in the init of dbhelper lib
Andrey Nering
@andreynering
Jun 28 2016 10:11
Thank you @sarathsp06 this will help. But I think the MySQL driver should properly handle thetime.Time type.