I know that Ember-Data is supposed to be compatible with Active Model Serializers by design, but they seem to be out of step on serializing has_many
relationships with embedded IDs.
For example, the serializer
class PostSerializer < ActiveModel::Serializer
embed :ids
has_many :comments
end
produces the JSON
{
"post": {
"comment_ids": [...]
}
}
But the default configuration in Ember Data,
App.Post = DS.Model.extend({
DS.hasMany('App.Comment'),
});
App.Comment = DS.Model.extend();
expects the comments association to be serialized as comments: [...]
without the _ids
suffix (see the relationships sub-section of the REST adapter section of the Ember.js guide).
I tried the following as a work-around:
class PostSerializer < ActiveModel::Serializer
attribute :comments
def comments
object.comment_ids
end
end
It works, but adding embed :ids, :include => true
in order to enable side-loading now does nothing since AMS doesn't know that it's an association.
Edit: I am using the active_model_serializers (0.6.0)
gem and Ember-Data revision 11