Fix Associations with slice of pointer

This commit is contained in:
Jinzhu 2015-02-17 23:36:23 +08:00
parent 73a0401678
commit 9b355ee86c
3 changed files with 5 additions and 2 deletions

View File

@ -14,7 +14,7 @@ func TestHasOneAndHasManyAssociation(t *testing.T) {
post := Post{ post := Post{
Title: "post 1", Title: "post 1",
Body: "body 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"}, Category: Category{Name: "Category 1"},
MainCategory: Category{Name: "Main Category 1"}, MainCategory: Category{Name: "Main Category 1"},
} }

View File

@ -25,6 +25,9 @@ type Scope struct {
func (scope *Scope) IndirectValue() reflect.Value { func (scope *Scope) IndirectValue() reflect.Value {
if scope.indirectValue == nil { if scope.indirectValue == nil {
value := reflect.Indirect(reflect.ValueOf(scope.Value)) value := reflect.Indirect(reflect.ValueOf(scope.Value))
if value.Kind() == reflect.Ptr {
value = value.Elem()
}
scope.indirectValue = &value scope.indirectValue = &value
} }
return *scope.indirectValue return *scope.indirectValue

View File

@ -146,7 +146,7 @@ type Post struct {
MainCategoryId int64 MainCategoryId int64
Title string Title string
Body string Body string
Comments []Comment Comments []*Comment
Category Category Category Category
MainCategory Category MainCategory Category
} }