Remove uncessary NeedPtr method

This commit is contained in:
Jinzhu 2016-01-17 17:12:19 +08:00
parent 4f84bf0d94
commit e38b1e0948
3 changed files with 2 additions and 13 deletions

View File

@ -418,7 +418,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).NeedPtr().autoMigrate().db
db = db.NewScope(value).autoMigrate().db
}
return db
}

View File

@ -35,16 +35,6 @@ func (scope *Scope) IndirectValue() reflect.Value {
return *scope.indirectValue
}
func (scope *Scope) NeedPtr() *Scope {
reflectKind := reflect.ValueOf(scope.Value).Kind()
if !((reflectKind == reflect.Invalid) || (reflectKind == reflect.Ptr)) {
err := fmt.Errorf("%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.NewDB(), Search: &search{}, Value: value}

View File

@ -63,8 +63,7 @@ func convertInterfaceToMap(values interface{}) map[string]interface{} {
attrs[ToDBName(key.Interface().(string))] = reflectValue.MapIndex(key).Interface()
}
default:
scope := Scope{Value: values}
for _, field := range scope.Fields() {
for _, field := range (&Scope{Value: values}).Fields() {
if !field.IsBlank && !field.IsIgnored {
attrs[field.DBName] = field.Field.Interface()
}