forked from mirror/gorm
Improve compatibility when set model
This commit is contained in:
parent
32dcacc70b
commit
600d8e7277
|
@ -404,20 +404,20 @@ func TestOrderAndPluck(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var ages1, ages2 []int64
|
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) {
|
if !reflect.DeepEqual(ages1, ages2) {
|
||||||
t.Errorf("The first order is the primary order")
|
t.Errorf("The first order is the primary order")
|
||||||
}
|
}
|
||||||
|
|
||||||
var ages3, ages4 []int64
|
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) {
|
if reflect.DeepEqual(ages3, ages4) {
|
||||||
t.Errorf("Reorder should works well")
|
t.Errorf("Reorder should works well")
|
||||||
}
|
}
|
||||||
|
|
||||||
ages = []int64{}
|
ages = []int64{}
|
||||||
var names []string
|
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) {
|
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")
|
t.Errorf("Should be ordered correctly with multiple orders")
|
||||||
}
|
}
|
||||||
|
|
3
model.go
3
model.go
|
@ -34,8 +34,7 @@ func (m *Model) primaryKeyValue() int64 {
|
||||||
if m.data == nil {
|
if m.data == nil {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
data := reflect.Indirect(reflect.ValueOf(m.data))
|
||||||
data := reflect.ValueOf(m.data).Elem()
|
|
||||||
|
|
||||||
switch data.Kind() {
|
switch data.Kind() {
|
||||||
case reflect.Array, reflect.Chan, reflect.Map, reflect.Ptr, reflect.Slice:
|
case reflect.Array, reflect.Chan, reflect.Map, reflect.Ptr, reflect.Slice:
|
||||||
|
|
Loading…
Reference in New Issue