Added UpdateFieldsWithoutHooks method

This commit is contained in:
Lukas Jorg 2023-06-29 12:05:53 +02:00 committed by Gerhard Gruber
parent 30a4f9bcaa
commit 246897fa79

View File

@ -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) 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 { func (db *DB) SelectFields(fields ...string) *DB {
selects := strings.Join(fields, ", ") selects := strings.Join(fields, ", ")