Search code examples
ember.jsadapterstore

Ember data Error: the adapter's response did not have any data


I just upgraded an app from Ember 1.13 to Ember 2.12. Now my attempts to load the data store are failing. This line:

return this.store.find('blog', 14);

generates this error: "Error while processing route: blogs.index Assertion Failed: You made a findRecord request for a blog with id 14, but the adapter's response did not have any data".

But the data is arriving, and in this format:

{ "blogs": { "id": 14, "person_id": "1", "access": "3" } }

My adapter is specified in application/adapter.js as:

export default DS.RESTAdapter.extend({

host: "http://localhost", namespace: 'api-rick'

});

Anyone know why I'm getting this error? I think the JSON is properly formatted -- didn't have any problems before I upgraded Ember.

Later EDIT, here's relevant code:

//application/adapter.js
import DS from 'ember-data';
import Ember from 'ember';
export default DS.RESTAdapter.extend({

  host: "http://localhost",
  namespace: 'api-rick',

  pathForType: function(type) {
    //this so types (db table names) are singular;
    //else are pluralized in Adapter's request
    return Ember.String.singularize(type);
  }
});

//application/serializer.js
port DS from 'ember-data';

export default DS.RESTSerializer.extend({
});

//pods/contact/model.js
import DS from 'ember-data';

export default DS.Model.extend({
  name         : DS.attr(),
});

//pods/contact/route.js
import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return this.store.findAll('contact');
  },
});

//payload returned when viewed in Chrome's developer tools (contact table has only the one record):

{
    "contact": [
        {
            "id": 1,
            "name": "Bilbo the duck"
        }
    ]
}

Finally, here's the errors reported in Chrome's console:

Transition #0: contact: calling beforeModel hook
ember.debug.js:55891 
Transition #0: contact: calling deserialize hook
ember.debug.js:28573 
Error while processing route: contact Assertion Failed: You made a `findAll` request for contact records, but the adapter's response did not have any data Error
    at assert (http://localhost:4200/assets/vendor.js:20732:13)
    at Object.assert (http://localhost:4200/assets/vendor.js:32400:34)
    at assert (http://localhost:4200/assets/vendor.js:85626:37)
    at http://localhost:4200/assets/vendor.js:97389:41
    at tryCatch (http://localhost:4200/assets/vendor.js:73561:14)
    at invokeCallback (http://localhost:4200/assets/vendor.js:73576:15)
    at publish (http://localhost:4200/assets/vendor.js:73544:9)
    at http://localhost:4200/assets/vendor.js:53448:16
    at invokeWithOnError (http://localhost:4200/assets/vendor.js:15377:16)
    at Queue.flush (http://localhost:4200/assets/vendor.js:15436:9)

Solution

  • If your backend is responding with underscore then you need to have the below code,

    import DS from 'ember-data';
    
    export default DS.RESTSerializer.extend({
      keyForAttribute: function(attr, method) {
        return Ember.String.underscore(attr);
      }
    });