Want to create a custom Serializer for Ember data? You will want to subclass DS.JSONSerializer, which supplies the basic behavior for dealing with JSON payloads. In particular, you will want to override the extractHasMany hook:
1 2 3 4 5 6 7 8 9 10 11 12 13 | // elsewhere in your file function singularize(key) { // remove the trailing `s`. You might want to store a hash of // plural->singular if you deal with names that don't follow // this pattern return key.substr(0, key.length - 1); } DS.JSONSerializer.extend({ extractHasMany: function(type, hash, key) { return hash[key][singularize(key)].id; } }) |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.