My legacy server JSON response looks like this:
{ "foo": { … }, "bars": ["a", "b", "c", …] }
How can I map this into an Ember Data Model by extending a RESTAdapter?
My best attempt so far is the following:
app/models/rule-lookup.js:
import DS from 'ember-data';
export default DS.Model.extend({
foo: DS.attr(),
bars: DS.attr(),
});
app/models/foo.js:
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
description: DS.attr('string'),
});
When the user makes a choice in a select, in the controller I fetch the model with:
this.store.findRecord('rule-lookup', id);
In the adapter (inside application.js) I have put the following statements:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
urlForFindRecord(id, modelName, snapshot) {
switch (modelName) {
case 'rule-lookup': {
return `api/keys/${id}/rules/0/200`;
}
}
},
});
But the error from findRecord is:
WARNING: Encountered "bars" in payload, but no model was found for model name "bar" (resolved model name using panel@serializer:rest:.modelNameFromPayloadKey("bars"))`
TypeError: Cannot read property '_internalModel' of undefined
Aucun commentaire:
Enregistrer un commentaire