Getting this error . Not sure why i am getting this error…would appreciate if someone can help me spot why this is erroring out.
Error while loading route: Error: Assertion Failed: You must include an id
in a hash passed to push
at new Error (native)
at Error.Ember.Error (http://localhost:8000/vendor/ember/ember.js:910:19)
at Object.Ember.assert (http://localhost:8000/vendor/ember/ember.js:73:11)
at Ember.Object.extend.push (http://localhost:8000/vendor/ember-data/ember-data.js:9882:15)
at null. (http://localhost:8000/vendor/ember-data/ember-data.js:9956:23)
at Array.map (native)
at Ember.EnumerableUtils.map (http://localhost:8000/vendor/ember/ember.js:1918:30)
at Ember.Object.extend.pushMany (http://localhost:8000/vendor/ember-data/ember-data.js:9955:16)
at JSONSerializer.extend.extractArray (http://localhost:8000/vendor/ember-data/ember-data.js:3184:19)
at superWrapper (http://localhost:8000/vendor/ember/ember.js:1292:16)
from the other posts related to similar error this has to do with a json where primary key is not handled correctly. But my json response looks correct.
here are model objects:
var PersonInfo = DS.Model.extend({
first: DS.attr('string'),
last : DS.attr('string'),
addresses: DS.hasMany('personAddress', {embedded: 'always'})
});
Ember.Inflector.inflector.irregular("personInfo", "peopleInfo");
export default PersonInfo;
var Address = DS.Model.extend({
type: DS.attr('string'),
personInfo: DS.belongsTo('personInfo')
});
export default Address;
**here is my deserializer:**
var PersonInfoSerializer = DS.ActiveModelSerializer.extend({
primaryKey: 'id',
extractArray: function(store, type, payload, id, requestType) {
var peopleInfo =payload.peopleInfo;
var adds = [];
// debugger;
peopleInfo.forEach(function(personInfo){
var addresses = personInfo.addresses,
addressIds = addresses.mapProperty('id');
adds.push(addresses);
personInfo.addresses = addressIds;
});
payload.addresses = adds;
return this._super(store, type, payload, id, requestType);
}
});
export default PersonInfoSerializer;
**and here is the json response which i am mocking in API STUB**
server.get('/peopleInfo', function(req, res) {
var person_info = {
"peopleInfo": [{
"id": "1",
"first": "Tom",
"last": "Dale",
"addresses": [{
"id": "1",
"type": "Home"
}, {
"id": "2",
"type": "Work"
}]
}]
};
res.send(person_info);
});