In my application I have model Game which has has_many
relation with model Stage, and model Stage which has has_many
relation with model Winning.
I'm having problem with serializing, as I want to have a response looking like this:
{
"game_id": 1,
"stages": [
{
"stage_id": 1,
"winnings": [
{
"winning_id": 1
},
{ ... }
]
},
{ ... }
]
}
However, when I serialize it like this:
class Admin::GameResultsSerializer < ActiveModel::Serializer
attribute :id
has_many :stages
class StageSerializer < ActiveModel::Serializer
attribute :id
has_many :winnings
class WinningSerializer < ActiveModel::Serializer
attribute :id
belongs_to :user
end
end
end
I does not return any winning in response - response only returns games with stages and I have no idea why.
Would appreciate help.