mirror of https://github.com/go-gorm/gorm.git
Fix "Unsupported destination" error when value is pointer of pointer
This commit is contained in:
parent
b870f86fba
commit
c730b30a78
|
@ -30,7 +30,7 @@ func queryCallback(scope *Scope) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if value, ok := scope.Get("gorm:query_destination"); ok {
|
if value, ok := scope.Get("gorm:query_destination"); ok {
|
||||||
results = reflect.Indirect(reflect.ValueOf(value))
|
results = indirect(reflect.ValueOf(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
if kind := results.Kind(); kind == reflect.Slice {
|
if kind := results.Kind(); kind == reflect.Slice {
|
||||||
|
|
|
@ -461,8 +461,10 @@ func TestScan(t *testing.T) {
|
||||||
t.Errorf("Scan into struct should work")
|
t.Errorf("Scan into struct should work")
|
||||||
}
|
}
|
||||||
|
|
||||||
var doubleAgeRes result
|
var doubleAgeRes = &result{}
|
||||||
DB.Table("users").Select("age + age as age").Where("name = ?", user3.Name).Scan(&doubleAgeRes)
|
if err := DB.Table("users").Select("age + age as age").Where("name = ?", user3.Name).Scan(&doubleAgeRes).Error; err != nil {
|
||||||
|
t.Errorf("Scan to pointer of pointer")
|
||||||
|
}
|
||||||
if doubleAgeRes.Age != res.Age*2 {
|
if doubleAgeRes.Age != res.Age*2 {
|
||||||
t.Errorf("Scan double age as age")
|
t.Errorf("Scan double age as age")
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@ func TestFirstAndLast(t *testing.T) {
|
||||||
DB.First(&user1)
|
DB.First(&user1)
|
||||||
DB.Order("id").Limit(1).Find(&user2)
|
DB.Order("id").Limit(1).Find(&user2)
|
||||||
|
|
||||||
DB.Last(&user3)
|
ptrOfUser3 := &user3
|
||||||
|
DB.Last(&ptrOfUser3)
|
||||||
DB.Order("id desc").Limit(1).Find(&user4)
|
DB.Order("id desc").Limit(1).Find(&user4)
|
||||||
if user1.Id != user2.Id || user3.Id != user4.Id {
|
if user1.Id != user2.Id || user3.Id != user4.Id {
|
||||||
t.Errorf("First and Last should by order by primary key")
|
t.Errorf("First and Last should by order by primary key")
|
||||||
|
|
Loading…
Reference in New Issue