Compare commits

..

2 Commits

2 changed files with 15 additions and 4 deletions

View File

@ -301,9 +301,9 @@ func (d *Document) Populate(fields ...string) {
for _, field := range fields {
// 0 = fieldname, 1 = typename, 2 = bson name
r, _ := readFields(field, cm)
r, refOk := cm.references[field]
if r.exists {
if refOk {
// get self
// get ptr
// find
@ -328,8 +328,11 @@ func (d *Document) Populate(fields ...string) {
asIDocument.markPopulated(field)
}
tmp1 = populate(r, refColl.collection, rawDoc, field, reflect.ValueOf(d.self).Interface())
d.self = tmp1
v := reflect.ValueOf(d.self)
tt := v.Elem().Type()
tmp1 = populate(r, refColl.collection, rawDoc, field, d.self)
nv := reflect.NewAt(tt, v.UnsafePointer())
nv.Elem().Set(reflect.ValueOf(tmp1).Elem())
}
}
}

View File

@ -611,10 +611,18 @@ func (q *Query) Exec(result interface{}) {
imodel, ok := cur.Interface().(IDocument)
if ok {
imodel.setExists(true)
imodel.SetSelf(imodel)
doc.Elem().Index(i).Set(reflect.ValueOf(imodel))
}
}
}
if idoc, ok := q.doc.(IDocument); ok {
idoc.SetSelf(result)
}
if rdoc, ok2 := result.(IDocument); ok2 {
rdoc.SetSelf(result)
}
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(q.doc).Elem())
q.done = true
}