From 9f2959959b50300127a9aa63ce7fd070182b597c Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 12 Mar 2015 12:11:38 +0800 Subject: [PATCH] Add error if query destination is not supported --- callback_query.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/callback_query.go b/callback_query.go index 2c16610c..888702de 100644 --- a/callback_query.go +++ b/callback_query.go @@ -1,6 +1,7 @@ package gorm import ( + "errors" "fmt" "reflect" ) @@ -26,13 +27,16 @@ func Query(scope *Scope) { } } - if dest.Kind() == reflect.Slice { + if kind := dest.Kind(); kind == reflect.Slice { isSlice = true destType = dest.Type().Elem() if destType.Kind() == reflect.Ptr { isPtr = true destType = destType.Elem() } + } else if kind != reflect.Struct { + scope.Err(errors.New("unsupported destination, should be slice or struct")) + return } scope.prepareQuerySql() @@ -59,6 +63,7 @@ func Query(scope *Scope) { var values = make([]interface{}, len(columns)) fields := scope.New(elem.Addr().Interface()).Fields() + for index, column := range columns { if field, ok := fields[column]; ok { if field.Field.Kind() == reflect.Ptr {