Skip to content

.save() removes attributes from model ? #36

Description

@peritus

Hey. Thanks for backbone-pouch, everything is very smooth so far :)

I'm porting an application that saves the models on a remote server via Backbone's XHR to PouchDB and backbone-pouchdb. In the current version, save() sends the complete JSON representation to the server and retrieves a complete JSON representation back from the server (I guess that's custom to my application, but I believe that is a nice REST architecture and allows the server to also change the document).

So, in Model.parse, my code (quoting http://backbonejs.org/#changelog 's 1.1.0 section here)

"extract[s] and vivify[s] incoming nested JSON into associated submodels. "

With backbone-pouchdb, however, the data argument for parse is always an object containing just _id and _rev, without the attributes that have just been saved, because of these lines:

response = {
  _id: response.id,
  _rev: response.rev
};

I'd propose to respond with this instead:

response = extend({}, model.toJSON(), {
  _id: response.id,
  _rev: response.rev
});

so the model doesn't think the the server (or PouchDB in this case) deleted all the attributes.

Also, one could argue to only call model.toJSON() once, but I wanted to discuss in general this first before making optimizations.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions