From 07e2d49b22b32d037bb283e46d92c5d6a09d95c9 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 15 Aug 2014 11:14:33 +0800 Subject: [PATCH] Fix invalid reflect value --- scope.go | 3 +++ structs_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/scope.go b/scope.go index 79952375..4b934bf0 100644 --- a/scope.go +++ b/scope.go @@ -267,6 +267,9 @@ func (scope *Scope) fieldFromStruct(fieldStruct reflect.StructField) *Field { if !field.IsIgnored { // parse association + if !indirectValue.IsValid() { + indirectValue = reflect.New(value.Type()) + } typ := indirectValue.Type() foreignKey := SnakeToUpperCamel(settings["FOREIGNKEY"]) associationForeignKey := SnakeToUpperCamel(settings["ASSOCIATIONFOREIGNKEY"]) diff --git a/structs_test.go b/structs_test.go index 02df18eb..dd2695ef 100644 --- a/structs_test.go +++ b/structs_test.go @@ -32,6 +32,7 @@ type User struct { IgnoreMe int64 `sql:"-"` IgnoreStringSlice []string `sql:"-"` Ignored struct{ Name string } `sql:"-"` + IgnoredPointer *User `sql:"-"` } type CreditCard struct {