Skip to content

Commit 58ffab8

Browse files
committed
fix
1 parent ebafebb commit 58ffab8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

callbacks/update.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package callbacks
22

33
import (
4-
"fmt"
54
"reflect"
65
"sort"
76

@@ -57,16 +56,17 @@ func BeforeUpdate(db *gorm.DB) {
5756
}
5857

5958
if called {
60-
fields := db.Statement.Schema.Fields
61-
for i := 0; i < len(fields); i++ {
62-
if fields[i].PrimaryKey {
59+
for _, field := range db.Statement.Schema.Fields {
60+
if field.PrimaryKey {
61+
continue
62+
}
63+
dbFieldName, ok := field.TagSettings["COLUMN"]
64+
if !ok {
6365
continue
6466
}
65-
6667
// compare with the copy value and update the field if there is a difference
67-
if !reflect.DeepEqual(rv.FieldByName(fields[i].Name).Interface(), rvClone.FieldByName(fields[i].Name).Interface()) {
68-
fmt.Println(rv.FieldByName(fields[i].Name).Interface(), rvClone.FieldByName(fields[i].Name).Interface())
69-
db.Statement.SetColumn(fields[i].DBName, rv.Field(i).Interface())
68+
if !reflect.DeepEqual(rv.FieldByName(field.Name).Interface(), rvClone.FieldByName(field.Name).Interface()) {
69+
db.Statement.SetColumn(dbFieldName, rv.FieldByName(field.Name).Interface())
7070
}
7171
}
7272
}

0 commit comments

Comments
 (0)