【发布时间】:2016-01-28 22:47:59
【问题描述】:
我正在使用带有 JSON API 适配器的最新 AMS v0.10.0.rc3。
到目前为止效果很好,并且正在添加一些我想更改的有用约定。
例如,假设我有一个 Post 序列化器和一个 Comment 序列化器,如下所示:
class Post < ActiveModel::Serializer
attributes :id, :title
has_many :comments
end
class Comment < ActiveModel::Serializer
attributes :id, :comment
belongs_to :post
end
然后,如果我请求 /posts/1,例如,我会得到以下信息
{
"data": {
"id": "1",
"type": "posts",
"attributes": {
"title": "My awesome title",
},
"relationships": {
"comments": {
"data": [
{
"id": "1",
"type": "comments"
},
{
"id": "2",
"type": "comments"
}
]
}
}
}
}
注意relationships 成员是如何出现的,并且根据spec 被标记为带有MAY 的可选成员。
这是一个很好的约定,我需要重写一些时间。
所以我的问题是:
- 如何在序列化程序或控制器级别删除
relationship成员?
(如果我遗漏了一些细节,请发表评论,我会更新问题。)
【问题讨论】:
标签: active-model-serializers json-api