2
votes

I am getting an Ember error when the response json root is singular.

json response:

{"subscription": {"id": "1"}}

error:

Assertion failed: Your server returned a hash with the key subscription but you have no mapping for it

model:

App.Subscription

If I pass a plural root key subscriptions in the json response, it works fine. I don't think I should have to do this though since the singular version is default behavior for active _model_serializers if there is only one resource to send.

Is this a bug in Ember or should I be doing something for this to be supported?

1

1 Answers

2
votes

What might help is to define plurals on your adapter. So in the case of a model called App.Subscription this could look like this:

App.Adapter = DS.RESTAdapter.extend();
App.Adapter.configure('plurals', { "subscription": "subscription" });

Edit

As for the .json one possible solution might be to hook into the buildURL function of your RESTAdapter and adding the .json suffix yourself. This could look something like this:

App.Adapter = DS.RESTAdapter.extend({
  buildURL: function(record, suffix) {
    var url = this._super(record, suffix);
    return url + ".json";
  }
})

This would make a request to http://localhost:4000//subscription.json

Hope it helps.