My rails backend renders a json response when I call .save() on my model. When doing a jquery ajax PUT request like this, I can retrieve the data returned (see below, data parameter) :
$.ajax({
type : 'PUT',
url: '/conversations/' + conversation.id + '/assignation',
dataType: 'json',
data: newAssignation,
success: function(data) {
conversation.get('content').pushObject(data)};
});
How can I retrieve rendered json when calling .save() method on my model?
self.store.find('conversation', conv.id).then(function(conversation){
conversation.set('status', 'opened');
conversation.save(); ** This returns json response that I want to retrieve **
});
When you do
record.save()
, the following things happen (as of Ember Data 1.0.0-beta-19.1):record.save()
.store.scheduleSave()
.store.flushPendingSave()
.adapter.updateRecord()
.serializer.serializeIntoHash
.adapter.buildURL
.serializer.extract()
->serializer.extractSave()
->serializer.extractSingle()
.serializer.normalizePayload()
which does nothing but you can override it to clean the payload.store.didSaveRecord()
method.didCommit
event on the model.record.save()
in item 1 resolves.Some steps are missing in this list, I only highlighted important ones. I encourage you to follow the whole procedure in the sources, I gave you enough references.
Now to your question. I suggest that you override the
serializer.extractSave()
method. There you can convert your backend's payload into the Ember format and fiddle with it. Don't forget to callthis.super()
with all the arguments and the modified payload so that Ember actually pushes it to the store!