From 246897fa790bb043b5a72c72aa6fa2b94f59438c Mon Sep 17 00:00:00 2001 From: Lukas Jorg Date: Thu, 29 Jun 2023 12:05:53 +0200 Subject: [PATCH] Added UpdateFieldsWithoutHooks method --- expression_ext.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/expression_ext.go b/expression_ext.go index 9a0a1404..c11d892e 100644 --- a/expression_ext.go +++ b/expression_ext.go @@ -601,6 +601,13 @@ func (db *DB) UpdateFields(fields ...string) *DB { return db.clone().Set("gorm:save_associations", false).Set("gorm:association_save_reference", false).Update(sets) } +// UpdateFieldsWithoutHooks updates the specified fields of the current model without calling any +// Update hooks and without touching the UpdatedAt column (if any exists). +// The specified fields have to be the names of the struct variables. +func (db *DB) UpdateFieldsWithoutHooks(fields ...string) *DB { + return db.clone().Set("gorm:update_column", true).UpdateFields(fields...) +} + func (db *DB) SelectFields(fields ...string) *DB { selects := strings.Join(fields, ", ")