I am using ember 2.7.0.I got the following data from resp API,
{
"accounts": [
{
"id": "57a3660793d4ba3a5b78a780",
"status": null,
"crid": "Someone",
"deleted": false,
"accountInfo": {
"iccid": "accountId",
"iccidValue": "accountValue"
},
"subscriptionInfo": null
},
{
"id": "57a3660793d4ba3a5b78a780",
"status": null,
"crid": "Someone",
"deleted": false,
"accountInfo": {
"iccid": "accountId",
"iccidValue": "accountValue"
},
"subscriptionInfo": null
}
],
"user": {
"id": "288607702394",
"isdn": "491622897075",
"pcc": null
}
}
Created Model for Customer which contain details of all the accounts,users etc:
Customer.js (Model)
export default DS.Model.extend({
device:DS.hasMany('device'),
user:DS.belongsTo('user')
});
accounts.js(Model)
status: DS.attr(),
id: DS.attr(),
status: DS.attr(),
crid: DS.attr(),
deleted: DS.attr(),
accountInfo: DS.attr(),
subscriptionInfo: DS.attr()
User.js (Model)
export default DS.Model.extend({
isdn: DS.attr(),
pcc: DS.attr()
});
Created serializer for all the above 3-Models
Customer.js
export default ApplicationSerializer.extend({
normalizeResponse(store, primaryModelClass, payload, id, requestType){
console.log("Entered normalizeResponse",payload );
return this._super(...arguments)
}
});
Device.js
export default ApplicationSerializer.extend({
primaryKey: 'id'
});
user.js
export default ApplicationSerializer.extend({
primaryKey: 'id'
});
Issue is while running the application i am getting the following issue in chrome console : Assertion Failed: You must include an 'id' for customer in an object passed to 'push'
I do not know how to assign 'id' for customer model.Actually i would like to assign user model id as customer model is that possible? How can achieve it in customer model serializer?In the normalizeResponse of customer serializer i am able to see my response.
Note : I cannot modify the rest response.So option is left with modification of ember data model.
The way i am calling the REST API GET in my controller is
var customer = this.store.findRecord('customer', this.get('customerID')).then((customer) => {
console.log("customer::",customer);
},(resp,status) => {
console.log("resp:status:",resp,status);
});
It always entered in to the error response.
Your help should be appreciable.
Aucun commentaire:
Enregistrer un commentaire