2020-06-05 16:23:20 +03:00
|
|
|
package callbacks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func callMethod(db *gorm.DB, fc func(value interface{}, tx *gorm.DB) bool) {
|
|
|
|
tx := db.Session(&gorm.Session{})
|
|
|
|
if called := fc(db.Statement.Dest, tx); !called {
|
|
|
|
switch db.Statement.ReflectValue.Kind() {
|
|
|
|
case reflect.Slice, reflect.Array:
|
2020-06-30 17:47:21 +03:00
|
|
|
db.Statement.CurDestIndex = 0
|
2020-06-05 16:23:20 +03:00
|
|
|
for i := 0; i < db.Statement.ReflectValue.Len(); i++ {
|
2020-06-30 17:47:21 +03:00
|
|
|
fc(reflect.Indirect(db.Statement.ReflectValue.Index(i)).Addr().Interface(), tx)
|
|
|
|
db.Statement.CurDestIndex++
|
2020-06-05 16:23:20 +03:00
|
|
|
}
|
|
|
|
case reflect.Struct:
|
|
|
|
fc(db.Statement.ReflectValue.Addr().Interface(), tx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|