Search code examples
ember.jsember-data

Remove model name from ember data json


Ember data send data to the server with the model name embedded.

{
    "part" {
       "name" : "test1",
       "quantity" : 12
    }
}

I want the "part" field removed from the response so it would look like:

{
   "name" : "test1",
   "quantity" : 12
}

I need this to be generic so it will work for any model in my store.


ok I found the part that does in RESTAdapter.

  serializeIntoHash: function(data, type, record, options) {
    var root = underscore(decamelize(type.typeKey));
    data[root] = this.serialize(record, options);
  },

I tried to remove the root part

serializeIntoHash: function(data, type, record, options) {
    data = this.serialize(record, options);
}

But it does not work, it response with {}


Solution

  • https://github.com/san650/ember-cli-page-object/issues/153

    Ember.merge is deprecated, use Ember.assign

    App.ApplicationSerializer = DS.RESTSerializer.extend({
      serializeIntoHash: function(hash, type, record, options) {
        Ember.assign(hash, this.serialize(record, options));
      }
    });