1
votes

I'm getting the following error in my console when trying to return results from a JSON api:

Error while loading route: Error: Assertion Failed: The response from a findAll must be an Array, not undefined

Ember Data contains data from my JSON API (see image)

View of Ember Data from the Ember Chrome inspector

Other than that my code is throwing no errors.

Any ideas?

EMBER APP:

App = Ember.Application.create();

App.ApplicationAdapter = DS.RESTAdapter;

App.ApplicationAdapter = DS.RESTAdapter.extend({
    url: 'http://127.0.0.1:3000',
    namespace: 'api'    
});

App.ApplicationSerializer = DS.RESTSerializer.extend({  
    primaryKey: '_id'
});

App.Store = DS.Store.extend({
    revision: 11,
    adapter: 'App.Adapter'
});

App.Users = DS.Model.extend({
    "firstName": DS.attr('string'),
    "secondName": DS.attr('string'),
    "shortName": DS.attr('string'),
    "emailAddress": DS.attr('string'),
    "password": DS.attr('string'),
    "group": DS.attr('string'),
    "charisma": DS.attr('string'),
    "focus": DS.attr('string'),
    "strength": DS.attr('string'),
    "dexterity": DS.attr('string'),
    "userType": DS.attr('string'),
    "dressType": DS.attr('string'),
    "skinType": DS.attr('string'),
    "__v": DS.attr('string'),
    "loggedInDate": DS.attr('string'),
    "loggedIn": DS.attr('string'),
    "dateRegistered": DS.attr('string')
});

App.User = DS.Model.extend({
    "firstName": DS.attr('string'),
    "secondName": DS.attr('string'),
    "shortName": DS.attr('string'),
    "emailAddress": DS.attr('string'),
    "password": DS.attr('string'),
    "group": DS.attr('string'),
    "charisma": DS.attr('string'),
    "focus": DS.attr('string'),
    "strength": DS.attr('string'),
    "dexterity": DS.attr('string'),
    "userType": DS.attr('string'),
    "dressType": DS.attr('string'),
    "skinType": DS.attr('string'),
    "__v": DS.attr('string'),
    "loggedInDate": DS.attr('string'),
    "loggedIn": DS.attr('string'),
    "dateRegistered": DS.attr('string')
});


App.Router.map(function() {
  // put your routes here
});

App.IndexRoute = Ember.Route.extend({
    renderTemplate: function () {
        this.render();
        this.render('nav', {
            outlet: 'nav'
        });
    },
    model: function() {
        return this.store.find('users');
    }
});

JSON

{
  "Users": [
    {
      "firstName": "Berniece",
      "secondName": "Bergstrom",
      "shortName": "april",
      "emailAddress": "[email protected]",
      "password": "PRPOP",
      "group": 1,
      "charisma": 4,
      "focus": 3,
      "strength": 3,
      "dexterity": 1,
      "userType": 1,
      "dressType": 2,
      "skinType": 1,
      "_id": "5302604e1a41219a2d2072eb",
      "__v": 0,
      "loggedInDate": "2014-02-17T19:17:34.725Z",
      "loggedIn": false,
      "dateRegistered": "2014-02-17T19:17:34.724Z"
    },
    {
      "firstName": "Lamar",
      "secondName": "Schneider",
      "shortName": "august.blick",
      "emailAddress": "[email protected]",
      "password": "PJPUK",
      "group": 0,
      "charisma": 2,
      "focus": 3,
      "strength": 1,
      "dexterity": 2,
      "userType": 1,
      "dressType": 2,
      "skinType": 2,
      "_id": "5302604e1a41219a2d2072ec",
      "__v": 0,
      "loggedInDate": "2014-02-17T19:17:34.728Z",
      "loggedIn": false,
      "dateRegistered": "2014-02-17T19:17:34.728Z"
    }
}
1

1 Answers

2
votes

Unless you the needs the Users model for something else, I'd throw it away and only use the user model. And change this code:

App.IndexRoute = Ember.Route.extend({
renderTemplate: function () {
    this.render();
    this.render('nav', {
        outlet: 'nav'
    });
},
model: function() {
    return this.store.find('user'); // Changed to user
}
});

This will return an array of the users and should work.

Also note, that your Users model is wrong. Since Users is an array of users, it does not need to contain all of the user properties. It should one property -- User. Here is the model should look :

App.Users = DS.Model.extend({
  user: DS.hasMany('user')
})