Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8094565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:49:51+00:00 2026-06-05T20:49:51+00:00

I am implementing an application using ember.js and couchdb. I choose ember-resource as database

  • 0

I am implementing an application using ember.js and couchdb. I choose ember-resource as database access layer because it nicely supports nested JSON documents.

Since couchdb uses the attribute _rev for optimistic locking in every document, this attribute has to be updated in my application after saving the data to the couchdb.

My idea to implement this is to reload the data right after saving to the database and get the new _rev back with the rest of the document.

Here is my code for this:

// Since we use CouchDB, we have to make sure that we invalidate and re-fetch
// every document right after saving it. CouchDB uses an optimistic locking
// scheme based on the attribute "_rev" in the documents, so we reload it in
// order to have the correct _rev value.
didSave:     function() {
    this._super.apply(this, arguments);
    this.forceReload();
},

// reload resource after save is done, expire to make reload really do something
forceReload: function() {
    this.expire();  // Everything OK up to this location
    Ember.run.next(this, function() {
        this.fetch()  // Sub-Document is reset here, and *not* refetched!
            .fail(function(error) {
                App.displayError(error);
            })
            .done(function() {
                App.log("App.Resource.forceReload fetch done, got revision " + self.get('_rev'));
            });
    });
}

This works for most cases, but if i have a nested model, the sub-model is replaced with the old version of the data just before the fetch is executed!

Interestingly enough, the correct (updated) data is stored in the database and the wrong (old) data is in the memory model after the fetch, although the _rev attribut is correct (as well as all attributes of the main object).

Here is a part of my object definition:

App.TaskDefinition = App.Resource.define({

url: App.dbPrefix + 'courseware',

schema: {
    id:          String,
    _rev:        String,
    type:        String,
    name:       String,
    comment:    String,
    task:        {
        type:   'App.Task',
        nested: true
    }
}
});

App.Task = App.Resource.define({

schema: {
    id: String,
    title:       String,
    description: String,

    startImmediate: Boolean,
    holdOnComment: Boolean,
    ..... // other attributes and sub-objects
}
});

Any ideas where the problem might be?

Thank’s a lot for any suggestion!

Kind regards,
Thomas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:49:54+00:00Added an answer on June 5, 2026 at 8:49 pm

    I found a much better solution to get the new revision back from the database, without reloading the data after every save.

    If save is called in ember-resource 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

    {"ok":true,"id":"mydocument-123","rev":"10-5f3cb46df301143a966251148f88663d"}
    

    So i just set the _rev property of my objects to the rev value from the db.

    My application specific resource class as superclass for all couchdb objects is as follows:

    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
    });
    

    The resources are defined like this:

    App.TaskExecution = App.Resource.define({
    
        ....
    
        schema: {
    
            id:   String,
            _rev: String,
            rev:  String,
            type: String,
            .....  // other attributes
        }
    
    });
    

    Works pretty well so far….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a message application using CouchDB. I want to apply timestamps to each
I am implementing a SaaS application using ASP.Net MVC 2 and SQL Server database.
I am implementing a Facebook application and using AJAX/JSON . However the JSON structures
I'm implementing a web - based application using silverlight with an SQL Server DB
I am currently implementing the application that displays hierarchy using ListBoxes (please do not
I am implementing input method related application in Android. In this application I'm using
I am implementing a comet using AsyncHttpHandlers in my current asp.net application. According to
I am implementing SOAP web services for a commercial application, and I am using
I am implementing an eCommerce application using ASP.Net. I would like to know if
We just finished implementing OAuth in our RoR application using the Twitter gem .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.