Skip to content

Instantly share code, notes, and snippets.

@ryanto
Created Feb 14, 2019
Embed
What would you like to do?
// app/pods/serializers/application.js
import DS from 'ember-data';
export default DS.JSONAPISerializer.extend({
normalize() {
let hash = this._super(...arguments);
if (hash.data && hash.data.relationships) {
let relationshipIdentifiers = hash.data.relationships;
let relationshipNames = Object.keys(relationshipIdentifiers);
relationshipNames.forEach(relationshipName => {
let relationshipIdentifier = relationshipIdentifiers[relationshipName];
if (!relationshipIdentifier.data) {
delete relationshipIdentifiers[relationshipName];
} else if (relationshipIdentifier.links) {
delete relationshipIdentifier.links;
}
});
}
return hash;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment