4
votes

I have been stuck on this issue for quite awhile now. I have thoroughly researched the issue on stackoverflow and was unable to find a solution.

I am trying to load JSON data into my application store with ember-data and a rails API. I am using ember-cli.

The error I am continuing to get is: Assertion Failed: Error: Assertion Failed: The response from a findAll must be an Array, not undefined

The application consists of several reports that each have charts. The server fires off a request to the API (with a uuid tacked on as a query string) and receives the following json response:

{
    reports: [
        {
            id: 1,
            name: "Report 1",
            description: "Test Report 1",
            display_order: 0,
            chart_ids: [
                1
            ]
        },
        {
            id: 2,
            name: "Report 2",
            description: "Test Report 2",
            display_order: 1,
            chart_ids: [
                5,
                6
            ]
        }
    ]
}

This is the route for reports:

export default Ember.Route.extend({
    setupController: function(controller) {
         controller.set('model', this.store.find('report'));
    }
});

And my models:

var Report = DS.Model.extend({
    name: DS.attr('string'),
    description: DS.attr('string'),
    displayOrder: DS.attr('integer'),
    charts: DS.hasMany('chart', { async: true })
 });

var Chart = DS.Model.extend({
    reports: DS.belongsTo('report'),
    config: DS.attr()
});

I am using an ActiveModelAdapter and an ActiveModelSerializer:

ApplicationAdapter:

export default DS.ActiveModelAdapter.extend({
    namespace: 'api',
    ajax: function(url, type, hash) {
        if (Ember.isEmpty(hash)) {
            hash = {};
        }

        if (Ember.isEmpty(hash.data)) {
            hash.data = {};
        }

        hash.data.uuid = $.cookie('uuid');
        this._super(url, type, hash);
    }
});

And serializer:

export default DS.ActiveModelSerializer.extend();

I'm so frustrated at the moment. Ember debugger isn't being very helpful. Any help would be super appreciated.

Let me know if any more info would be helpful.

1
what's the response from server when it requests the chart info, or is it not doing that?Kingpin2k
It shouldn't be requesting any chart data until I click on a report. So it isn't making a request for that.Mike L.
You aren't referencing it in the template or anything are you?Kingpin2k
I am in the chart template, but even on the a page without the chart template I am still getting the error. I can provide the chart json response as well if that would be helpful.Mike L.
I totally missed the adapter, you overrode the ajax method, but failed to return the value from the super.Kingpin2k

1 Answers

0
votes

I'm pretty sure this needs to be charts_ids instead of chart_ids (note the s after chart) in the JSON response for reports.

or change your hasMany to chart (though that seems weird)

 var Report = DS.Model.extend({
    name: DS.attr('string'),
    description: DS.attr('string'),
    displayOrder: DS.attr('integer'),
    chart: DS.hasMany('chart', { async: true })
 });

You're not returning the ajax.

App.ApplicationAdapter= DS.ActiveModelAdapter.extend({
  namespace: 'api',
    ajax: function(url, type, hash) {
        if (Ember.isEmpty(hash)) {
            hash = {};
        }

        if (Ember.isEmpty(hash.data)) {
            hash.data = {};
        }

        hash.data.uuid = $.cookie('uuid');
        return this._super(url, type, hash);
    }
});

http://emberjs.jsbin.com/OxIDiVU/678/edit