我试图得到一个JSON,它看起来像这样
{
"data" : {
"type": "field_definition",
"id": 5,
"attributes": {
"specifier": "foo",
"entity_type": "bar"
}
"relationships": {
"active_collections" : [1,2,3]
}
}
}
class Test
attr_reader :id,
:specifier,
:entity_type,
:active_collections
def initialize
@id = 5
@specifier = "foo"
@entity_type = "bar"
@active_collections = [1,2,3]
end
end
class SerializableFieldCollection < JSONAPI::Serializable::Resource
type 'field_collection'
attributes :specifier, :entity_type
has_many :active_collections
end
def index
render jsonapi: Test.new,
class: SerializableFieldCollection,
status: 200
end
{"data"=>
{"id"=>"5", "type"=>"field_collection", "attributes"=>{"specifier"=>"foo", "entity_type"=>"bar"}, "relationships"=>{"active_collections"=>{"meta"=>{"included"=>false}}}}}
有人能告诉我如何使用jsonapi rb gem中的relationships/has_many函数吗?