Fixes getPrimaryKey for non struct type
This commit is contained in:
parent
1fc176d679
commit
2eb6a38fce
2
scope.go
2
scope.go
@ -247,7 +247,7 @@ func (scope *Scope) Fields() []*Field {
|
||||
|
||||
// Search for primary key tag identifier
|
||||
field.isPrimaryKey = scope.PrimaryKey() == field.DBName || fieldStruct.Tag.Get("primaryKey") != ""
|
||||
fmt.Printf("Name: %s\n isPrimaryKey: %v\n\n", field.DBName, field.isPrimaryKey)
|
||||
|
||||
if field.isPrimaryKey {
|
||||
scope.primaryKey = field.DBName
|
||||
}
|
||||
|
@ -475,7 +475,13 @@ func (scope *Scope) autoMigrate() *Scope {
|
||||
}
|
||||
|
||||
func (scope *Scope) getPrimaryKey() string {
|
||||
indirectValue := reflect.Indirect(reflect.ValueOf(scope.Value))
|
||||
var indirectValue reflect.Value
|
||||
|
||||
indirectValue = reflect.Indirect(reflect.ValueOf(scope.Value))
|
||||
|
||||
if indirectValue.Kind() == reflect.Slice {
|
||||
indirectValue = reflect.New(indirectValue.Type().Elem()).Elem()
|
||||
}
|
||||
|
||||
if !indirectValue.IsValid() {
|
||||
return "id"
|
||||
|
Loading…
x
Reference in New Issue
Block a user