Encode and decode when copying a document

This commit is contained in:
Tobie Morgan Hitchcock 2018-08-20 01:06:52 +01:00
parent 445436bff7
commit 31ad063ef4
2 changed files with 4 additions and 4 deletions

View file

@ -236,8 +236,9 @@ func (d *document) setup(ctx context.Context) (err error) {
// maniuplate the virtual document.
if d.doc != nil {
d.initial = d.doc
d.current = d.doc.Copy()
enc := d.doc.Encode()
d.initial = data.New().Decode(enc)
d.current = data.New().Decode(enc)
}
// The requested record has been loaded

View file

@ -22,7 +22,6 @@ import (
"encoding/json"
"github.com/abcum/surreal/util/deep"
"github.com/abcum/surreal/util/pack"
)
@ -67,7 +66,7 @@ func (d *Doc) Data() interface{} {
// Copy returns a duplicated copy of the internal data object.
func (d *Doc) Copy() *Doc {
return &Doc{data: deep.Copy(d.data)}
return new(Doc).Decode(d.Encode())
}
// Encode encodes the data object to a byte slice.