Radhian Amri
Radhian Amri

Reputation: 347

Gorm save without updating updated_at column

I noticed when calling the db.Save() method, the column updated_at also gets updated. Have checked the docs and it seems that way as well: https://gorm.io/docs/update.html

Is there anyway to prevent this?

Upvotes: 1

Views: 2861

Answers (1)

Radhian Amri
Radhian Amri

Reputation: 347

I found solution by adding the following line after initializing db connection:

db.GetConnection().Callback().Update().Remove("gorm:update_time_stamp")

I found this when checking through the following code: https://sourcegraph.com/github.com/jinzhu/gorm/-/blob/callback_update.go#L20:75

There are multiple callbacks being called by default when an Update is done. So the fix was to remove it.

Upvotes: 1

Related Questions