From 9107c9dea138bff0fcdc552ac9de48bbc849ef04 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Thu, 8 Jun 2017 20:46:15 -0700 Subject: [PATCH] Another instance of helper slices in eager code - Another instance of helper slice types seeping in. Convert the slice when it's found as part of a singular's R struct. - Fix #158 --- queries/eager_load.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/queries/eager_load.go b/queries/eager_load.go index d4ede9c..be62bbd 100644 --- a/queries/eager_load.go +++ b/queries/eager_load.go @@ -206,9 +206,16 @@ func (l loadRelationshipState) loadRelationshipsRecurse(depth int, obj reflect.V } bkind := kindStruct - if reflect.Indirect(loadedObject).Kind() != reflect.Struct { + if derefed := reflect.Indirect(loadedObject); derefed.Kind() != reflect.Struct { bkind = kindPtrSliceStruct - loadedObject = loadedObject.Addr() + + // Convert away any helper slice types + // elemType is *elem (from []*elem or helperSliceType) + // sliceType is *[]*elem + elemType := derefed.Type().Elem() + sliceType := reflect.PtrTo(reflect.SliceOf(elemType)) + + loadedObject = loadedObject.Addr().Convert(sliceType) } return l.loadRelationships(depth+1, loadedObject.Interface(), bkind) }