I have to override extractSingle
method in DS.RESTSerializer
. See the emberjs link in the code for details.
// http://stackoverflow.com/questions/14320925/how-to-make-embedded-hasmany-relationships-work-with-ember-data
// http://emberjs.com/api/data/classes/DS.RESTSerializer.html#method_extractSingle
App.PollSerializer = DS.RESTSerializer.extend({
extractSingle: function(store, type, payload, id) {
var poll = payload.poll;
var choices = poll.choices;
delete poll.choices;
poll.choices = [];
choices.forEach(function(c) {
poll.choices.push(c.id);
});
payload = { choices: choices, poll: payload.poll };
return this._super(store, type, payload, id);
}
});
This turns my original structure into standard form.
Note: Ignorant fool that downvoted, is there a simpler way to do this, am i in some kind of pitfall, explain yourself.