fix panic caused by unsafe slice-casting operation in model.go
This commit is contained in:
parent
a91f4b6af8
commit
a44b9679aa
10
model.go
10
model.go
@ -7,7 +7,6 @@ import (
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Model - type which contains "static" methods like
|
||||
@ -111,7 +110,12 @@ func (m *Model) Find(query interface{}, opts *options.FindOptionsBuilder) (*Quer
|
||||
op: OP_FIND_ALL,
|
||||
}
|
||||
q, err := m.FindRaw(query, opts)
|
||||
idoc := (*DocumentSlice)(unsafe.Pointer(qqv.Elem().UnsafeAddr()))
|
||||
//idoc := (*DocumentSlice)(qqv.Elem().UnsafePointer())
|
||||
idoc := make(DocumentSlice, 0)
|
||||
for i := 0; i < qqv.Elem().Len(); i++ {
|
||||
idoc = append(idoc, qqv.Elem().Index(i).Interface().(IDocument))
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
rawRes := bson.A{}
|
||||
err = q.All(context.TODO(), &rawRes)
|
||||
@ -125,7 +129,7 @@ func (m *Model) Find(query interface{}, opts *options.FindOptionsBuilder) (*Quer
|
||||
qq.reOrganize()
|
||||
err = nil
|
||||
}
|
||||
for _, doc := range *idoc {
|
||||
for _, doc := range idoc {
|
||||
doc.setModel(*m)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user