{"action":"created","issue":{"url":"https://api.github.com/repos/jashkenas/backbone/issues/3734","labels_url":"https://api.github.com/repos/jashkenas/backbone/issues/3734/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/backbone/issues/3734/comments","events_url":"https://api.github.com/repos/jashkenas/backbone/issues/3734/events","html_url":"https://github.com/jashkenas/backbone/issues/3734","id":97547167,"number":3734,"title":"Deferring updates until first save succeeds","user":{"login":"dgsan","id":313910,"avatar_url":"https://avatars.githubusercontent.com/u/313910?v=3","gravatar_id":"","url":"https://api.github.com/users/dgsan","html_url":"https://github.com/dgsan","followers_url":"https://api.github.com/users/dgsan/followers","following_url":"https://api.github.com/users/dgsan/following{/other_user}","gists_url":"https://api.github.com/users/dgsan/gists{/gist_id}","starred_url":"https://api.github.com/users/dgsan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgsan/subscriptions","organizations_url":"https://api.github.com/users/dgsan/orgs","repos_url":"https://api.github.com/users/dgsan/repos","events_url":"https://api.github.com/users/dgsan/events{/privacy}","received_events_url":"https://api.github.com/users/dgsan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-27T20:23:47Z","updated_at":"2015-07-27T20:45:40Z","closed_at":null,"body":"What is the generally accepted method of delaying additional updates until the first save succeeds (with a model)? \r\n\r\nI'm trying to avoid an issue where save ends up creating additional entries server side because the first few saves all end up getting treated as `create` (POST) requests, I guess because of latency with the first save. I'll see something like POST `{first_name: \"John\"}`, POST `{first_name: \"John\", last_name: \"Doe\"}`, instead of the second request being a PUT for `first_name` and `last_name`, and then end up with multiple DB rows that are near identical as fields are sequentially filled in.\r\n\r\nI tried the simple solution of deferring saves with deferred objects, but that just seems to lead to the hash sent back from the server's first save clobbering any local changes before the deferred save fires.\r\n\r\nThought I'd check before writing something complicated that queues/merges pending changes. Most of the related google results seem to be from several years ago (and haven't worked in tests).\r\n"},"comment":{"url":"https://api.github.com/repos/jashkenas/backbone/issues/comments/125337322","html_url":"https://github.com/jashkenas/backbone/issues/3734#issuecomment-125337322","issue_url":"https://api.github.com/repos/jashkenas/backbone/issues/3734","id":125337322,"user":{"login":"tsjoberg","id":7171881,"avatar_url":"https://avatars.githubusercontent.com/u/7171881?v=3","gravatar_id":"","url":"https://api.github.com/users/tsjoberg","html_url":"https://github.com/tsjoberg","followers_url":"https://api.github.com/users/tsjoberg/followers","following_url":"https://api.github.com/users/tsjoberg/following{/other_user}","gists_url":"https://api.github.com/users/tsjoberg/gists{/gist_id}","starred_url":"https://api.github.com/users/tsjoberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsjoberg/subscriptions","organizations_url":"https://api.github.com/users/tsjoberg/orgs","repos_url":"https://api.github.com/users/tsjoberg/repos","events_url":"https://api.github.com/users/tsjoberg/events{/privacy}","received_events_url":"https://api.github.com/users/tsjoberg/received_events","type":"User","site_admin":false},"created_at":"2015-07-27T20:45:40Z","updated_at":"2015-07-27T20:45:40Z","body":"The save event is an async event so without looking at your code you can try to use the models ```'sync'``` event and listen to that event prior to calling additional updates. \r\n\r\nhttp://backbonejs.org/#Events-catalog\r\n\r\nYou can also add a ```success``` callback to the save options as shown in the docs too which is called if 200 response is returned:\r\n\r\nhttp://backbonejs.org/#Model-save\r\n\r\nHowever you will probably need this and other functionality (ex. disabling submit button on ```request``` (or debouncing the actual save to make sure you send the latest data on multiple clicks) and re-enabling submit on successful save etc. These are just a few ideas but hopefully that helps."}}