EmberTricks[1]: Overwriting data store
I had a form that after submit could be modified on the backend. I needed to handle this and display the newly modified form.
The success callback doesn't have any reference to status codes so I handled it in error
this.store.pushPayload is a pretty cool guy and will push a bunch of stuff into the store. A bunch of stuff is necessary. It will only push pluralized models in the payload. ie. users, posts not user, post. If you have any singulars you will have to munge the payload to pluralize the keys and wrap the data in an array.
Render the response as normal with an error status. I used code 409 to indicate a conflict
In the error callback you have access to an object that includes the status code and the response in responseJSON.
When the error is my custom status, I this.store.pushPayload(errorObject.responseJSON)
Now, this is the weird bit. I had the misconception that updating the models will overwrite the most recent changes as the "canonical changes" however this is not the case. Any changes you have made on the front end will still stick around. You actually need to record.rollback() for the model to reflect what you backend has returned.