forked from mirror/gorm
Remove uncessary NeedPtr method
This commit is contained in:
parent
4f84bf0d94
commit
e38b1e0948
2
main.go
2
main.go
|
@ -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
|
||||
}
|
||||
|
|
10
scope.go
10
scope.go
|
@ -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}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue