Encode and decode when copying a document
This commit is contained in:
parent
445436bff7
commit
31ad063ef4
2 changed files with 4 additions and 4 deletions
|
@ -236,8 +236,9 @@ func (d *document) setup(ctx context.Context) (err error) {
|
||||||
// maniuplate the virtual document.
|
// maniuplate the virtual document.
|
||||||
|
|
||||||
if d.doc != nil {
|
if d.doc != nil {
|
||||||
d.initial = d.doc
|
enc := d.doc.Encode()
|
||||||
d.current = d.doc.Copy()
|
d.initial = data.New().Decode(enc)
|
||||||
|
d.current = data.New().Decode(enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The requested record has been loaded
|
// The requested record has been loaded
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/abcum/surreal/util/deep"
|
|
||||||
"github.com/abcum/surreal/util/pack"
|
"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.
|
// Copy returns a duplicated copy of the internal data object.
|
||||||
func (d *Doc) Copy() *Doc {
|
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.
|
// Encode encodes the data object to a byte slice.
|
||||||
|
|
Loading…
Reference in a new issue