Model with type attribute



My API return a JSON like this one:

      "content": "abc",
      "type": "number"

The attribute “type” seems to be deleted by ember, how i can update the json key “type” before ember delete it ?

I cannot modify the API behavior.

In an serializer ? In what method ?



What do you mean “deleted by ember”? What kind of adapter are you using right now?


I’m a little surprised you’re not also running into problems with the content keyword, as that is where I had problems with it. I think that Ember Data just has reserved words that make it so attributes of that type won’t work. I got around it by doing this in my serializer (not sure if this is the best way, but it works).

keyForAttribute(attr, method) {
  if(attr === 'modelContent') {
    return 'content';
  } else {
    return Ember.String.underscore(attr);

Where modelContent is the property defined on my ED model, and content is the key I get in the response from my JSON. You could certainly do something similar with type.

Another option would be to change it in normalize response. Either way, you have to make sure that the property on the ED model doesn’t clash with the reserved word (in my case content, in yours type).


It was a mistake from my API, thank you for the answer anyway