Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 {}

like image 203
jax Avatar asked Dec 20 '22 13:12

jax


2 Answers

OK found it: 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));
  }
});
like image 144
jax Avatar answered Dec 27 '22 07:12

jax


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));
  }
});
like image 40
reaz Avatar answered Dec 27 '22 06:12

reaz