Remove model name from ember json data

Ember data sends data to a server with an embedded model name.

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

I want the "part" field to be removed from the response so that it looks like this:

{
   "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 works in the 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, its answer is with {}

+4
source share
2 answers

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

Ember.merge outdated use Ember.assign

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

OK found: https://github.com/emberjs/data/issues/771

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

Source: https://habr.com/ru/post/1547132/


All Articles