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 {
|
func (s *DB) AutoMigrate(values ...interface{}) *DB {
|
||||||
db := s.clone()
|
db := s.clone()
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
db = db.NewScope(value).NeedPtr().autoMigrate().db
|
db = db.NewScope(value).autoMigrate().db
|
||||||
}
|
}
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
10
scope.go
10
scope.go
@ -35,16 +35,6 @@ func (scope *Scope) IndirectValue() reflect.Value {
|
|||||||
return *scope.indirectValue
|
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
|
// New create a new Scope without search information
|
||||||
func (scope *Scope) New(value interface{}) *Scope {
|
func (scope *Scope) New(value interface{}) *Scope {
|
||||||
return &Scope{db: scope.NewDB(), Search: &search{}, Value: value}
|
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()
|
attrs[ToDBName(key.Interface().(string))] = reflectValue.MapIndex(key).Interface()
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
scope := Scope{Value: values}
|
for _, field := range (&Scope{Value: values}).Fields() {
|
||||||
for _, field := range scope.Fields() {
|
|
||||||
if !field.IsBlank && !field.IsIgnored {
|
if !field.IsBlank && !field.IsIgnored {
|
||||||
attrs[field.DBName] = field.Field.Interface()
|
attrs[field.DBName] = field.Field.Interface()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user