Skip to content

Instantly share code, notes, and snippets.

@snewcomer
Created September 24, 2016 14:21
Show Gist options
  • Save snewcomer/f5fa179fee6ca7f40d549ae75e2fb16d to your computer and use it in GitHub Desktop.
Save snewcomer/f5fa179fee6ca7f40d549ae75e2fb16d to your computer and use it in GitHub Desktop.
/* app/serializers/application.js */
normalizeFindRecordResponse(store, primaryModelClass, payload) {
const _p = payload.data;
const relationships = _p.relationships;
if (relationships) {
Object.keys(_p.relationships).forEach((related_key) => {
// m2m
if (Array.isArray(relationships[related_key].data)) {
_p.attributes[`${related_key}-ids`] = relationships[related_key].data.mapBy(‘id’);
// belongs_to
} else if (relationships[related_key].data) {
_p.attributes[`${related_key}-id`] = relationships[related_key].data.id;
}
});
}
return this._super(…arguments);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment