From 3db4f30f564e65e40f5467f76692501c21489a46 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Wed, 19 Aug 2020 23:43:39 -0400 Subject: [PATCH] Fix multi-depth eager loading of relationships. If a relationship is nil, do not add it to the collection for checking the next depth level. --- queries/eager_load.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/queries/eager_load.go b/queries/eager_load.go index 962d722..8992290 100644 --- a/queries/eager_load.go +++ b/queries/eager_load.go @@ -5,9 +5,9 @@ import ( "reflect" "strings" - "github.com/pkg/errors" "github.com/lbryio/sqlboiler/boil" "github.com/lbryio/sqlboiler/strmangle" + "github.com/pkg/errors" ) type loadRelationshipState struct { @@ -259,9 +259,13 @@ func collectLoaded(key string, loadingFrom reflect.Value) (reflect.Value, bindKi for { switch bkind { case kindStruct: - collection = reflect.Append(collection, loadedObject) + if !loadedObject.IsNil() { + collection = reflect.Append(collection, loadedObject) + } case kindPtrSliceStruct: - collection = reflect.AppendSlice(collection, loadedObject) + if !loadedObject.IsNil() { + collection = reflect.AppendSlice(collection, loadedObject) + } } i++ -- 2.45.3