fast_jsonapi
fast_jsonapi copied to clipboard
How to Avoid including relationships of relationship
I wanted to avoid including the relationships while including relationship. How can I achieve that? For Example,
class MovieSerializer
include FastJsonapi::ObjectSerializer
attributes :name, :year
has_many :actors
belongs_to :owner
belongs_to :movie_type
end
class ActorSerializer
include FastJsonapi::ObjectSerializer
attributes :name, :rating
belongs_to :movie
end
options = {:include=>[:movie]}
ActorSerializer.new(Actor.first,options).serializable_hash
gives me
{
"data":{
"id":"1",
"type":"actor",
"attributes":{
"name":"Robin",
"rating":5
},
"relationships":{
"movie":{
"data":{
"id":"1",
"type":"movie"
}
}
}
},
"included":[
{
"id":null,
"type":"movie",
"attributes":{
"name":null,
"year":null
},
"relationships":{
"actors":{
"data":[ ]
},
"owner":{
"data":null
},
"movie_type":{
"data":null
}
}
}
]
}
Question is How can I avoid, the relationship portion
"relationships":{ "actors":{ "data":[ ] }, "owner":{ "data":null }, "movie_type":{ "data":null }}
that comes along with the included movie. I need the relationship while serializing movie but not while serializing actors.