forked from mirror/gorm
22 lines
520 B
Go
22 lines
520 B
Go
|
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:
|
||
|
for i := 0; i < db.Statement.ReflectValue.Len(); i++ {
|
||
|
fc(db.Statement.ReflectValue.Index(i).Addr().Interface(), tx)
|
||
|
}
|
||
|
case reflect.Struct:
|
||
|
fc(db.Statement.ReflectValue.Addr().Interface(), tx)
|
||
|
}
|
||
|
}
|
||
|
}
|