Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
demoManito committed Aug 26, 2024
1 parent ebafebb commit 58ffab8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions callbacks/update.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package callbacks

import (
"fmt"
"reflect"
"sort"

Expand Down Expand Up @@ -57,16 +56,17 @@ func BeforeUpdate(db *gorm.DB) {
}

if called {
fields := db.Statement.Schema.Fields
for i := 0; i < len(fields); i++ {
if fields[i].PrimaryKey {
for _, field := range db.Statement.Schema.Fields {
if field.PrimaryKey {
continue
}
dbFieldName, ok := field.TagSettings["COLUMN"]
if !ok {
continue
}

// compare with the copy value and update the field if there is a difference
if !reflect.DeepEqual(rv.FieldByName(fields[i].Name).Interface(), rvClone.FieldByName(fields[i].Name).Interface()) {
fmt.Println(rv.FieldByName(fields[i].Name).Interface(), rvClone.FieldByName(fields[i].Name).Interface())
db.Statement.SetColumn(fields[i].DBName, rv.Field(i).Interface())
if !reflect.DeepEqual(rv.FieldByName(field.Name).Interface(), rvClone.FieldByName(field.Name).Interface()) {
db.Statement.SetColumn(dbFieldName, rv.FieldByName(field.Name).Interface())
}
}
}
Expand Down

0 comments on commit 58ffab8

Please sign in to comment.