diff --git a/boil/reflect.go b/boil/reflect.go index 54d379e..72a1eaa 100644 --- a/boil/reflect.go +++ b/boil/reflect.go @@ -176,7 +176,7 @@ func loadRelationships(exec Executor, toLoad []string, obj interface{}, singular if loadedObject.IsNil() { return nil } - loadedObject = loadedObject.Elem() + loadedObject = reflect.Indirect(loadedObject) // If it's singular we can just immediately call without looping if singular { @@ -205,8 +205,11 @@ func loadRelationshipsRecurse(exec Executor, current string, toLoad []string, si if !r.IsValid() || r.IsNil() { return errors.Errorf("could not traverse into loaded %s relationship to load more things", current) } - newObj := r.Elem().FieldByName(current) - singular = newObj.Elem().Kind() == reflect.Struct + newObj := reflect.Indirect(r).FieldByName(current) + singular = reflect.Indirect(newObj).Kind() == reflect.Struct + if !singular { + newObj = newObj.Addr() + } return loadRelationships(exec, toLoad, newObj.Interface(), singular) } diff --git a/boil/reflect_test.go b/boil/reflect_test.go index 94a68dc..04f0e68 100644 --- a/boil/reflect_test.go +++ b/boil/reflect_test.go @@ -182,7 +182,7 @@ type testNestedSlice struct { R *testNestedRSlice } type testNestedRSlice struct { - ToEagerLoad *[]*testNestedSlice + ToEagerLoad []*testNestedSlice } func (r *testRStruct) LoadTestOne(exec Executor, singular bool, obj interface{}) error { @@ -211,12 +211,14 @@ func (r *testNestedRSlice) LoadToEagerLoad(exec Executor, singular bool, obj int switch x := obj.(type) { case *testNestedSlice: - newSlice := []*testNestedSlice{&testNestedSlice{ID: 5}} - x.R = &testNestedRSlice{&newSlice} + x.R = &testNestedRSlice{ + []*testNestedSlice{&testNestedSlice{ID: 5}}, + } case *[]*testNestedSlice: - newSlice := []*testNestedSlice{&testNestedSlice{ID: 5}} for _, r := range *x { - r.R = &testNestedRSlice{&newSlice} + r.R = &testNestedRSlice{ + []*testNestedSlice{&testNestedSlice{ID: 5}}, + } } } loadFunctionNestedCalled++