diff --git a/main.go b/main.go index ec974cae..af626b06 100644 --- a/main.go +++ b/main.go @@ -363,7 +363,7 @@ func (s *DB) HasTable(value interface{}) bool { func (s *DB) AutoMigrate(values ...interface{}) *DB { db := s.clone() for _, value := range values { - db = db.NewScope(value).autoMigrate().db + db = db.NewScope(value).NeedPtr().autoMigrate().db } return db } diff --git a/scope.go b/scope.go index 0af4dc8e..8c09cedc 100644 --- a/scope.go +++ b/scope.go @@ -34,14 +34,20 @@ func (scope *Scope) IndirectValue() reflect.Value { // NewScope create scope for callbacks, including DB's search information func (db *DB) NewScope(value interface{}) *Scope { - // reflectKind := reflect.ValueOf(value).Kind() - // if !((reflectKind == reflect.Invalid) || (reflectKind == reflect.Ptr)) { - // fmt.Printf("%v %v\n", fileWithLineNum(), "using unaddressable value") - // } db.Value = value return &Scope{db: db, Search: db.search, Value: value} } +func (scope *Scope) NeedPtr() *Scope { + reflectKind := reflect.ValueOf(scope.Value).Kind() + if !((reflectKind == reflect.Invalid) || (reflectKind == reflect.Ptr)) { + err := errors.New(fmt.Sprintf("%v %v\n", fileWithLineNum(), "using unaddressable value")) + scope.Err(err) + fmt.Printf(err.Error()) + } + return scope +} + // New create a new Scope without search information func (scope *Scope) New(value interface{}) *Scope { return &Scope{db: scope.db, Search: &search{}, Value: value}