mirror of https://github.com/go-gorm/gorm.git
Fix Associations with slice of pointer
This commit is contained in:
parent
73a0401678
commit
9b355ee86c
|
@ -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"},
|
||||||
}
|
}
|
||||||
|
|
3
scope.go
3
scope.go
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue