From 7fe81acec6b8ea9af91775b96faa66dd50809308 Mon Sep 17 00:00:00 2001 From: Daniel Sullivan Date: Sun, 6 Oct 2019 14:44:35 +0900 Subject: [PATCH] Prevent primary key from being changed when doing an update on Interface based queries --- callback_update.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/callback_update.go b/callback_update.go index 699e534b..196ba029 100644 --- a/callback_update.go +++ b/callback_update.go @@ -69,8 +69,13 @@ func updateCallback(scope *Scope) { sort.Strings(columns) for _, column := range columns { - value := updateMap[column] - sqls = append(sqls, fmt.Sprintf("%v = %v", scope.Quote(column), scope.AddToVars(value))) + // Get the field data + field, _ := scope.FieldByName(column) + + if !field.IsPrimaryKey { + value := updateMap[column] + sqls = append(sqls, fmt.Sprintf("%v = %v", scope.Quote(column), scope.AddToVars(value))) + } } } else { for _, field := range scope.Fields() {