1
votes

I am trying to follow http://emberjs.com/guides/models/connecting-to-an-http-server/ for using ember data but after creating the rest apis I am getting js error like :

Error while loading route:

TypeError: data is undefined

on code :

Ember.assert("You must include an id in a hash passed to push", data.id != null);

I initially thought that I needed to include "id" field on the model I created but then if I do so, it throws error saying I should not put id field in the model. The output form the rest API is correct:

{
"analyticsRun": {
    "id": 1,
    "analyticsPlan": "some plan",
    "commandScript": "some script",
    "analyticsRunParameters": [
        "homeDir",
        "historyDir",
        "Sourcefolder",
        "resultsDir",
        "dataDir"
    ]
},
"analyticsRunParameters": [
    {
        "id": "homeDir",
        "default": "Some default",
        "description": "Where is the analytics folder",
        "name": "homeDir",
        "value": "Q:/Ember",
        "type": "global"
    },
    {
        "id": "historyDir",
        "default": "Rhistory",
        "description": "Where R image will be saved",
        "name": "historyDir",
        "value": "Rhistory",
        "type": "global"
    },
    {
        "id": "Sourcefolder",
        "default": "J:/Analytics_R_Source_Scripts",
        "description": "Where are source codes and functions are saved",
        "name": "Sourcefolder",
        "value": "J:/_R_Source_Scripts",
        "type": "type 1"
    },
    {
        "id": "resultsDir",
        "default": "results",
        "description": "Where are results stored",
        "name": "resultsDir",
        "value": "results",
        "type": "global"
    },
    {
        "id": "dataDir",
        "default": "Export",
        "description": "Where is raw csv stored",
        "name": "dataDir",
        "value": "Export",
        "type": "global"
    }
]
}

My models are defined as :

AS.AnalyticsRun = DS.Model.extend({
'analyticsPlan' : DS.attr('string'),
'commandScript' : DS.attr('string'),
'parameters'    : DS.hasMany('analyticsRunParameter')
});

AS.AnalyticsRunParameter = DS.Model.extend({
'name'          : DS.attr('string'),
'type'          : DS.attr('string'),
'description'   : DS.attr('string'),
'default'       : DS.attr('string'),
'value'         : DS.attr('string')
});

And my route is :

AS.AnalyticsConfigRoute = Ember.Route.extend({
model: function(param) {
    var store = this.get('store');
    return store.find('AnalyticsRun',param.runId);
}
});    

From the error it seems like the code is doing an id lookup and failing to find it. Has anyone faced this issue before or do you have any suggestions as to how to solve this issue?

NOTE : the isuse seems to be caused in the ember-data.js file in the _find function.

return resolve(promise).then(function(payload) {
Ember.assert("You made a request for a " + type.typeKey + " with id " + id + ", but the      adapter's response did not have any data", payload);
//payload has data here
payload = serializer.extract(store, type, payload, id, 'find');
//payload is undefined here!!
return store.push(type, payload);
}

Thanks, Dee

1
What's the payload in where it has data? Is it the json from above? Does the id match the payloadKingpin2k

1 Answers

1
votes

Okay, so I'm setting up a JSBIn, until then I'll keep looking for issues (I'm far more familiar with Ember Model).

Did you try setting analyticsRun to lower case on your find?

 model: function(param) {
   var store = this.get('store');
   return store.find('analyticsRun',param.runId);
 }