4

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.

Mike L.
  • 148
  • 1
  • 7
  • what's the response from server when it requests the chart info, or is it not doing that? – Kingpin2k Jun 18 '14 at 17:18
  • 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. Jun 18 '14 at 17:19
  • You aren't referencing it in the template or anything are you? – Kingpin2k Jun 18 '14 at 17:26
  • 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. Jun 18 '14 at 17:28
  • I totally missed the adapter, you overrode the ajax method, but failed to return the value from the super. – Kingpin2k Jun 18 '14 at 20:26

1 Answers1

0

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

Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
  • Unfortunately I'm still getting the same error. Looking through ember's documentation, it looks like ActiveModelAdapter should handle any of the rails to ember incongruities. Would that be included or is this something to note in the future? – Mike L. Jun 18 '14 at 17:37
  • Sorry, I ran off to lunch, do you actually have an Integer transform? – Kingpin2k Jun 18 '14 at 20:22
  • 1
    Returning the ajax fixed the problem! Thanks so much! – Mike L. Jun 18 '14 at 20:27