Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found a much better solution to get the new revision back from the database, without reloading the data after every save.</p> <p>If <code>save</code> is called in <code>ember-resource</code> with an update option, the response from the db is merged into the resource object. The answer of couchdb to the save request is something like</p> <pre><code>{"ok":true,"id":"mydocument-123","rev":"10-5f3cb46df301143a966251148f88663d"} </code></pre> <p>So i just set the <code>_rev</code> property of my objects to the <code>rev</code> value from the db.</p> <p>My application specific resource class as superclass for all couchdb objects is as follows:</p> <pre><code>App.Resource = Ember.Resource.extend({ save: function(options) { options = options || {}; options.update = true; // sets id and rev after saving in ember-resource; rev is copied to _rev in didSave callback! this.set('rev', undefined); return this._super(options); }, // we get the new revision in the "rev" attribute of the response from the save-request. // since we set options.update to true, we get this value in the attribute "rev", which we simply copy to "_rev" didSave: function() { this._super.apply(this, arguments); this.set('_rev', this.get('rev')); } .... // other properties and functions }); </code></pre> <p>The resources are defined like this:</p> <pre><code>App.TaskExecution = App.Resource.define({ .... schema: { id: String, _rev: String, rev: String, type: String, ..... // other attributes } }); </code></pre> <p>Works pretty well so far....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload