From 0d5d18437e7cd947bd5f445c4d5281d492ebcd72 Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Sun, 19 May 2019 00:45:52 +0200 Subject: [PATCH] Fix preload field type assertion --- mongox/common/common.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mongox/common/common.go b/mongox/common/common.go index 490259d..01f0275 100644 --- a/mongox/common/common.go +++ b/mongox/common/common.go @@ -110,14 +110,16 @@ func createAggregateLoad(db *mongox.Database, target interface{}, composed *quer continue } - isPtr := el.Field(i).Kind() == reflect.Ptr isSlice := el.Field(i).Kind() == reflect.Slice - isIface := el.Field(i).CanInterface() - if (!isPtr && !isSlice) || !isIface { - continue - } typ := el.Field(i).Type() + if typ.Kind() == reflect.Slice { + typ = typ.Elem() + } + if typ.Kind() != reflect.Ptr { + panic("preload field should have ptr type") + } + lookupCollection := db.GetCollectionOf(reflect.Zero(typ).Interface()) lookupVars := primitive.M{"selector": "$" + localField} lookupPipeline := primitive.A{