diff --git a/gorm_test.go b/gorm_test.go index 4fa3bcaf..7bd12e21 100644 --- a/gorm_test.go +++ b/gorm_test.go @@ -404,20 +404,20 @@ func TestOrderAndPluck(t *testing.T) { } var ages1, ages2 []int64 - db.Model(&[]User{}).Order("age desc").Pluck("age", &ages1).Order("age").Pluck("age", &ages2) + db.Model([]User{}).Order("age desc").Pluck("age", &ages1).Order("age").Pluck("age", &ages2) if !reflect.DeepEqual(ages1, ages2) { t.Errorf("The first order is the primary order") } var ages3, ages4 []int64 - db.Model(&[]User{}).Order("age desc").Pluck("age", &ages3).Order("age", true).Pluck("age", &ages4) + db.Model(&User{}).Order("age desc").Pluck("age", &ages3).Order("age", true).Pluck("age", &ages4) if reflect.DeepEqual(ages3, ages4) { t.Errorf("Reorder should works well") } ages = []int64{} var names []string - db.Model(&User{}).Order("name").Order("age desc").Pluck("age", &ages).Pluck("name", &names) + db.Model(User{}).Order("name").Order("age desc").Pluck("age", &ages).Pluck("name", &names) if !(names[0] == "1" && names[2] == "3" && names[3] == "3" && ages[2] == 24 && ages[3] == 22) { t.Errorf("Should be ordered correctly with multiple orders") } diff --git a/model.go b/model.go index b1ffe585..3c79cb1e 100644 --- a/model.go +++ b/model.go @@ -34,8 +34,7 @@ func (m *Model) primaryKeyValue() int64 { if m.data == nil { return -1 } - - data := reflect.ValueOf(m.data).Elem() + data := reflect.Indirect(reflect.ValueOf(m.data)) switch data.Kind() { case reflect.Array, reflect.Chan, reflect.Map, reflect.Ptr, reflect.Slice: