diff --git a/model_struct.go b/model_struct.go index ed8e579f..3e43768d 100644 --- a/model_struct.go +++ b/model_struct.go @@ -103,7 +103,11 @@ func (scope *Scope) GetModelStruct() *ModelStruct { if reflectValue.Kind() == reflect.Slice { reflectValue = reflect.Indirect(reflect.New(reflectValue.Type().Elem())) } + scopeType := reflectValue.Type() + if scopeType.Kind() == reflect.Ptr { + scopeType = scopeType.Elem() + } if scopeType.Kind() != reflect.Struct { return &modelStruct diff --git a/scope.go b/scope.go index 1185be9d..034f9e03 100644 --- a/scope.go +++ b/scope.go @@ -96,7 +96,7 @@ func (scope *Scope) HasError() bool { func (scope *Scope) PrimaryKeyField() *Field { if field := scope.GetModelStruct().PrimaryKeyField; field != nil { - return scope.getField(field) + return scope.Fields()[field.DBName] } return nil }