github.com/systematiccaos/gorm@v1.22.6/callbacks/callmethod.go (about)

     1  package callbacks
     2  
     3  import (
     4  	"reflect"
     5  
     6  	"github.com/systematiccaos/gorm"
     7  )
     8  
     9  func callMethod(db *gorm.DB, fc func(value interface{}, tx *gorm.DB) bool) {
    10  	tx := db.Session(&gorm.Session{NewDB: true})
    11  	if called := fc(db.Statement.ReflectValue.Interface(), tx); !called {
    12  		switch db.Statement.ReflectValue.Kind() {
    13  		case reflect.Slice, reflect.Array:
    14  			db.Statement.CurDestIndex = 0
    15  			for i := 0; i < db.Statement.ReflectValue.Len(); i++ {
    16  				fc(reflect.Indirect(db.Statement.ReflectValue.Index(i)).Addr().Interface(), tx)
    17  				db.Statement.CurDestIndex++
    18  			}
    19  		case reflect.Struct:
    20  			fc(db.Statement.ReflectValue.Addr().Interface(), tx)
    21  		}
    22  	}
    23  }