backbone-offline icon indicating copy to clipboard operation
backbone-offline copied to clipboard

Problem updating model with id from server

Open cslarson opened this issue 11 years ago • 4 comments

Hi, I'm using backbone.offline with the {autoPush: true} option in my collections. The response from the server on model create is like {id: "xxxxxx-xxxx-xxx...."} but the model sid is not updating with this new value. On inspection the success callback in backbone.offline (line 407) expects arguments (response, status, xhr) but it looks like in my case I'm getting the model as argument 1, and the response as argument 2. Looking at the Backbone.ajaxSync method it's possible that the success callback is being called like this:

    options.success = function(resp) {
      if (success) success(model, resp, options);
      model.trigger('sync', model, resp, options);
    };

which corresponds to what I'm seeing. Any ideas where I might have gone wrong?

cslarson avatar Jan 27 '13 18:01 cslarson

yes, this has to do with the success callback signature changing in v0.9.10. i've made changes in a fork (https://github.com/cslarson/cslarson.github.com), but they wouldn't be compatible with previous versions of backbone.js. It looks like the work on v0.9.10 compatibility was trying to maintain compatibility with previous versions.

cslarson avatar Jan 28 '13 10:01 cslarson

Sorry, could you provide the correct link to that fork, please?

hardchor avatar Mar 19 '13 17:03 hardchor

@hardchor I’d guess here.

backspace avatar Mar 19 '13 17:03 backspace

Not sure if it's the same issue but I have noticed the following: when I create a new model, it gets saved to the localstroage and also to the backend server correctly. BUT the sid is not filled with a value. When refreshing the page, (when the fetch is called) the sid is correctly filled and I can do operations like destroy on the model. But for the newly created models, I cannot call destroy since the sid is undefined. What is the reason for this? Should autoPush: true be used here? Even if sometimes my client is offline?

bbence84 avatar Mar 29 '13 12:03 bbence84