From 9b355ee86cc90957db4da5aa82feb3df3fb040dc Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 17 Feb 2015 23:36:23 +0800 Subject: [PATCH] Fix Associations with slice of pointer --- association_test.go | 2 +- scope.go | 3 +++ structs_test.go | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/association_test.go b/association_test.go index 51a61f09..6079454b 100644 --- a/association_test.go +++ b/association_test.go @@ -14,7 +14,7 @@ func TestHasOneAndHasManyAssociation(t *testing.T) { post := Post{ Title: "post 1", Body: "body 1", - Comments: []Comment{{Content: "Comment 1"}, {Content: "Comment 2"}}, + Comments: []*Comment{{Content: "Comment 1"}, {Content: "Comment 2"}}, Category: Category{Name: "Category 1"}, MainCategory: Category{Name: "Main Category 1"}, } diff --git a/scope.go b/scope.go index db26c677..c0e35f2e 100644 --- a/scope.go +++ b/scope.go @@ -25,6 +25,9 @@ type Scope struct { func (scope *Scope) IndirectValue() reflect.Value { if scope.indirectValue == nil { value := reflect.Indirect(reflect.ValueOf(scope.Value)) + if value.Kind() == reflect.Ptr { + value = value.Elem() + } scope.indirectValue = &value } return *scope.indirectValue diff --git a/structs_test.go b/structs_test.go index acd4cc74..95c1ea38 100644 --- a/structs_test.go +++ b/structs_test.go @@ -146,7 +146,7 @@ type Post struct { MainCategoryId int64 Title string Body string - Comments []Comment + Comments []*Comment Category Category MainCategory Category }