Browse files

Allow app to retrieve Vclock from a Model

  • Loading branch information...
1 parent 256eff9 commit 5cf4dcc977257dd37082a1159f22a6400d61fb7e @tpjg committed Feb 26, 2013
Showing with 8 additions and 2 deletions.
  1. +6 −0 model.go
  2. +2 −2 model_test.go
View
6 model.go
@@ -506,6 +506,12 @@ func (m *Model) Reload() (err error) {
return
}
+// Return the object Vclock - this allows an application to detect whether Reload()
+// loaded a newer version of the object
+func (m *Model) Vclock() (vclock []byte) {
+ return m.robject.Vclock
+}
+
// Get a models Key, e.g. needed when Riak has picked it
func (c *Client) Key(dest interface{}) (key string, err error) {
// Check destination
View
4 model_test.go
@@ -311,10 +311,10 @@ func TestModelReload(t *testing.T) {
err = doc2.Save()
assert.T(t, err == nil)
- vclock := string(doc.robject.Vclock)
+ vclock := string(doc.Vclock())
err = (&doc).Reload()
assert.T(t, err == nil)
- assert.T(t, string(doc.robject.Vclock) != vclock)
+ assert.T(t, string(doc.Vclock()) != vclock)
assert.T(t, string(doc.robject.Vclock) == string(doc2.robject.Vclock))
assert.T(t, doc.FieldS == doc2.FieldS)
assert.T(t, doc.FieldF == doc2.FieldF)

0 comments on commit 5cf4dcc

Please sign in to comment.