Ember-DataはActive Modelシリアライザと互換性があるとわかっていますが、組み込みのあるhas_many
のシリアライズID。例えばは、IDとサイドローディングが埋め込まれたEmber-DataモデルとActive Modelシリアライザのhas_manyコンフィグレーション
、シリアライザ
class PostSerializer < ActiveModel::Serializer
embed :ids
has_many :comments
end
は
App.Post = DS.Model.extend({
DS.hasMany('App.Comment'),
});
App.Comment = DS.Model.extend();
コメントアソシエーションがcomments: [...]
としてシリアル化されることを想定し、エンバーデータにJSON
{
"post": {
"comment_ids": [...]
}
}
が、デフォルト設定を生成します_ids
接尾辞なし(the relationships sub-section of the REST adapter section of the Ember.js guide)。
私は回避策として、次のことを試してみました:
class PostSerializer < ActiveModel::Serializer
attribute :comments
def comments
object.comment_ids
end
end
それは動作しますが、AMSは、それは協会のことを知らないので、今サイドローディングを有効にするためにembed :ids, :include => true
を追加すると、何もしません。
編集:私は11
これはおそらく最も合理的な回避策です。 – ahmacleod