Reputation: 5902
I have the following Ember.js model:
Filters.Milestone = DS.Model.extend({
id: DS.attr('string'),
name: DS.attr('string')
});
In my app.js I have the following settings for the model (loaded prior to the model):
Filters.MilestoneSerializer = DS.RESTSerializer.extend();
Filters.MilestoneAdapter = DS.RESTAdapter.extend({
namespace: "ember"
});
When loading the page, an AJAX call to the milestones list is done. The following JSON is returned:
{
"milestones": [
{
"id": "1",
"name": "Test Milestone #1"
}
]
}
When the JSON is loaded, the following error is returned:
TypeError: Cannot call method 'hasOwnProperty' of undefined
at e (http://sandbox.local/ember/js/libs/ember-data.js:8:30934)
at null.<anonymous> (http://sandbox.local/ember/js/libs/ember-data.js:8:31181)
at ComputedPropertyPrototype.set (http://sandbox.local/ember/js/libs/ember-1.4.0.js:4903:18)
at new Class (http://sandbox.local/ember/js/libs/ember-1.4.0.js:12652:18)
at Function.Mixin.create.create (http://sandbox.local/ember/js/libs/ember-1.4.0.js:13104:12)
at Ember.Object.extend.buildRecord (http://sandbox.local/ember/js/libs/ember-data.js:10:2880)
at Ember.Object.extend.recordForId (http://sandbox.local/ember/js/libs/ember-data.js:9:31214)
at Ember.Object.extend._load (http://sandbox.local/ember/js/libs/ember-data.js:10:2048)
at Ember.Object.extend.push (http://sandbox.local/ember/js/libs/ember-data.js:10:2450)
at null.<anonymous> (http://sandbox.local/ember/js/libs/ember-data.js:10:2701)
What am I doing wrong? I have tried following the same structure as https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/adapter/rest_adapter_test.js#L465. If I rename the milestones key it says that no model could be found for the new key, so something must be right :-)
Thanks in advance.
The route that I use is the following:
Filters.FiltersRoute = Ember.Route.extend({
model: function() {
return this.store.find('milestone')
}
});
If this.store.find('milestone')
is not called the error doesn't occur. Also, if I use the FixtureAdapter
instead of the RESTAdapter
, the error still occurs. So it seems that this might be related to the model, not the data source.
Upvotes: 2
Views: 2937
Reputation: 5902
The problem was caused by the id
attribute in the model. Apparently this should not be part of the model.
Upvotes: 9