I am using ember cli mirage with my amber app, i have data defined in fixtures and using the RestSerializer, i am trying to simulate updating the attributes of a record but getting an error: The patch handler for the url api/survey-groups/[id] threw an error: cannot read property update of null
mirage/config.js
this.patch('/survey-groups/:id', function({ surveyGroups }, request) {
let id = request.params.id;
let attrs = this.normalizedRequestAttrs();
return surveyGroups.find(id).update(attrs);
});
mirage/serializers/application.js
import { RestSerializer } from 'ember-cli-mirage';
export default RestSerializer.extend({
primaryKey: 'keyId'});
app/serializers/application.js
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
primaryKey: 'keyId', });
sample of fixture; mirage/fixtures/survey-groups.js
export default [
{
"code": "dfdj",
"description": "",
"keyId": 29116,
},
{...... }]
I also noticed in the data returned by the server that an id attribute was added to each record, with a string value e.g. id: "1" When i attempt to find a record using this string value in place of the id, the record is returned.
What could be causing this error and behavior
Aucun commentaire:
Enregistrer un commentaire