我正在使用 FastJsonapi 序列化对象。
class AuthorSerializer
include JSONAPI::Serializer
attributes :email, :username
has_many :publications, key: :posts
end
这里的问题是,FastJsonapi 提供的 key: :posts 仅将响应中的类型显示为帖子而不是出版物。
"username": "John"
},
"relationships": {
"posts": {
"data": [
{
"id": "1",
"type": "post"
}
]
},
但是对于包含参数,它仍然必须是 include[]=publications(实际表的名称)
render json: AuthorSerializer.new(@authors, {params[:include]}).serializable_hash.to_json, status: status
如果我输入 ../authors?include[]=publications,它可以工作。但是对于 include[]=posts,它不会。是否可以使用 FastJsonapi 更改它?