Fix preload field type assertion

v2
Nikita Tokarchuk 6 years ago
parent e973a52a88
commit 0d5d18437e
  1. 12
      mongox/common/common.go

@ -110,14 +110,16 @@ func createAggregateLoad(db *mongox.Database, target interface{}, composed *quer
continue continue
} }
isPtr := el.Field(i).Kind() == reflect.Ptr
isSlice := el.Field(i).Kind() == reflect.Slice isSlice := el.Field(i).Kind() == reflect.Slice
isIface := el.Field(i).CanInterface()
if (!isPtr && !isSlice) || !isIface {
continue
}
typ := el.Field(i).Type() 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()) lookupCollection := db.GetCollectionOf(reflect.Zero(typ).Interface())
lookupVars := primitive.M{"selector": "$" + localField} lookupVars := primitive.M{"selector": "$" + localField}
lookupPipeline := primitive.A{ lookupPipeline := primitive.A{

Loading…
Cancel
Save