File tree 1 file changed +8
-8
lines changed
1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 1
1
package callbacks
2
2
3
3
import (
4
- "fmt"
5
4
"reflect"
6
5
"sort"
7
6
@@ -57,16 +56,17 @@ func BeforeUpdate(db *gorm.DB) {
57
56
}
58
57
59
58
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 {
63
65
continue
64
66
}
65
-
66
67
// 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 ())
70
70
}
71
71
}
72
72
}
You can’t perform that action at this time.
0 commit comments