Created
September 24, 2016 14:21
-
-
Save snewcomer/f5fa179fee6ca7f40d549ae75e2fb16d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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