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.

This commit is contained in:
Mark Beamer Jr 2020-08-19 23:43:39 -04:00
parent 256a6d4225
commit 3db4f30f56
No known key found for this signature in database
GPG key ID: 1C314FB89AD76973

View file

@ -5,9 +5,9 @@ import (
"reflect" "reflect"
"strings" "strings"
"github.com/pkg/errors"
"github.com/lbryio/sqlboiler/boil" "github.com/lbryio/sqlboiler/boil"
"github.com/lbryio/sqlboiler/strmangle" "github.com/lbryio/sqlboiler/strmangle"
"github.com/pkg/errors"
) )
type loadRelationshipState struct { type loadRelationshipState struct {
@ -259,9 +259,13 @@ func collectLoaded(key string, loadingFrom reflect.Value) (reflect.Value, bindKi
for { for {
switch bkind { switch bkind {
case kindStruct: case kindStruct:
collection = reflect.Append(collection, loadedObject) if !loadedObject.IsNil() {
collection = reflect.Append(collection, loadedObject)
}
case kindPtrSliceStruct: case kindPtrSliceStruct:
collection = reflect.AppendSlice(collection, loadedObject) if !loadedObject.IsNil() {
collection = reflect.AppendSlice(collection, loadedObject)
}
} }
i++ i++