When I navigate to a specific page, the overridden function normalizeResponse
in my serializer used in conjunction with code in my router model
function, to add meta data to my model, works correctly. Basically, normalizeResponse
runs first, then my model
function in my router.
serializers/application.js
import App from '../app';
import JSONAPISerializer from 'ember-data/serializers/json-api';
App.storeMeta = {};
export default JSONAPISerializer.extend({
normalizeResponse(store, primaryModelClass, payload){
App.storeMeta[primaryModelClass.modelName] = payload.meta;
return this._super(...arguments);
}
});
And in my model.
model(params){
const data = {};
return this.store.findRecord('myModelType', params.id).then((myModelType)=>{
myModelType.meta = App.storeMeta['myModelType'];
return myModelType;
},()=>{ //error
this.get('session').invalidate();
});
}
When I navigate to that specific page through a link_to
from another page, the model code gets called first, so there is no meta data being attached to the model.
How do I get the normalizeResponse
function to run before the model
function when navigated to from link_to
?
Any help would greatly be appreciated.
Aucun commentaire:
Enregistrer un commentaire