From c730b30a7830a04a4a3d536edcb1f8c5f77d3482 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 7 Feb 2017 08:32:18 +0800 Subject: [PATCH] Fix "Unsupported destination" error when value is pointer of pointer --- callback_query.go | 2 +- main_test.go | 6 ++++-- query_test.go | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/callback_query.go b/callback_query.go index e2edd396..4ed1705e 100644 --- a/callback_query.go +++ b/callback_query.go @@ -30,7 +30,7 @@ func queryCallback(scope *Scope) { } 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 { diff --git a/main_test.go b/main_test.go index 9869a7ad..f76988d2 100644 --- a/main_test.go +++ b/main_test.go @@ -461,8 +461,10 @@ func TestScan(t *testing.T) { t.Errorf("Scan into struct should work") } - var doubleAgeRes result - DB.Table("users").Select("age + age as age").Where("name = ?", user3.Name).Scan(&doubleAgeRes) + var doubleAgeRes = &result{} + 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 { t.Errorf("Scan double age as age") } diff --git a/query_test.go b/query_test.go index 0aceaf80..d6b23ddf 100644 --- a/query_test.go +++ b/query_test.go @@ -18,7 +18,8 @@ func TestFirstAndLast(t *testing.T) { DB.First(&user1) DB.Order("id").Limit(1).Find(&user2) - DB.Last(&user3) + ptrOfUser3 := &user3 + DB.Last(&ptrOfUser3) DB.Order("id desc").Limit(1).Find(&user4) if user1.Id != user2.Id || user3.Id != user4.Id { t.Errorf("First and Last should by order by primary key")