Add reset to other load functions

v2
Nikita Tokarchuk 6 years ago
parent dad0a0598b
commit 61621c0a3a
  1. 9
      mongox/common/loadarray.go
  2. 3
      mongox/common/loadone.go

@ -4,6 +4,7 @@ import (
"reflect" "reflect"
"github.com/mainnika/mongox-go-driver/mongox" "github.com/mainnika/mongox-go-driver/mongox"
"github.com/mainnika/mongox-go-driver/mongox/base"
"github.com/mainnika/mongox-go-driver/mongox/errors" "github.com/mainnika/mongox-go-driver/mongox/errors"
"github.com/mainnika/mongox-go-driver/mongox/query" "github.com/mainnika/mongox-go-driver/mongox/query"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
@ -58,8 +59,12 @@ func LoadArray(db *mongox.Database, target interface{}, filters ...interface{})
} else { } else {
continue continue
} }
} else if err = result.Decode(targetSliceV.Index(i).Interface()); err != nil { } else {
continue elem := targetSliceV.Index(i).Interface()
base.Reset(elem)
if err = result.Decode(elem); err != nil {
continue
}
} }
i++ i++

@ -2,6 +2,7 @@ package common
import ( import (
"github.com/mainnika/mongox-go-driver/mongox" "github.com/mainnika/mongox-go-driver/mongox"
"github.com/mainnika/mongox-go-driver/mongox/base"
"github.com/mainnika/mongox-go-driver/mongox/errors" "github.com/mainnika/mongox-go-driver/mongox/errors"
"github.com/mainnika/mongox-go-driver/mongox/query" "github.com/mainnika/mongox-go-driver/mongox/query"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
@ -30,5 +31,7 @@ func LoadOne(db *mongox.Database, target interface{}, filters ...interface{}) er
return errors.NotFoundErrorf("can't find result: %s", result.Err()) return errors.NotFoundErrorf("can't find result: %s", result.Err())
} }
base.Reset(target)
return result.Decode(target) return result.Decode(target)
} }

Loading…
Cancel
Save