Getting rendered json from ember.save () method

My backend rails render a json response when I call .save () on my model. When doing a jQuery ajax PUT request like this, I can get the returned data (see the data parameter below):

$.ajax({
    type : 'PUT',
    url: '/conversations/' + conversation.id + '/assignation',
    dataType: 'json',
    data: newAssignation,
    success: function(data) {
        conversation.get('content').pushObject(data)};       
});

      

How can I get the processed json when the .save () method is called in 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 **           

});

      

+3


source to share


1 answer


When you execute record.save()

, the following things happen (as of Ember Data 1.0.0-beta-19.1):



Some steps are missing from this list, I've only highlighted the important ones. I urge you to follow the entire procedure in the sources, I have given you enough links.

Now to your question. I suggest you override the method serializer.extractSave()

. There you can convert your payload to Ember format and play with it. Remember to call this.super()

with all the arguments and the modified payload so that Ember will actually push it back into the store!

+4


source







All Articles