I have a mocked api endpoint with ember-cli-mirage and with some metadata. I did override the model serializer to add that metadata like this:
import { JSONAPISerializer } from 'ember-cli-mirage';
export default JSONAPISerializer.extend({
serialize(object, request) {
let json = JSONAPISerializer.prototype.serialize.apply(this, arguments);
json.meta = {
compass_size: 1,
arrow_size: 2,
total: 3
}
return json;
}
});
The api call returns that metadata correctly:
Object
data: Array[10]
meta: Object
arrow_size: 2
compass_size: 1
total: 3
...
Given I have this route handler:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').findAll('events');
}
});
When I try to print that data on my template
{{ model.meta.compass_size }}
then nothing is rendered. Am I missing something?
You need to override
normalizeResponse
hook to interpret the server(mirage) response.To change the format of the data that is sent to the backend store, you can use the
serialize()
hook. so in your case your backend(mirage) provides data in a format other than JSON API, you can use thenormalizeResponse()
hook.Reference