I have a rails application with deeply nested associations.
.-< WorkPeriod
Timecard -< Week -< Day -&
I had a similar issue. I fixed it in my controller. I like the idea of putting it in the serializer, but having it in the controller catches the n+1 weeks problem created by the ArraySerializer too.
Timecard.find(params[:id]).includes(weeks: [{ days: [:sub_totals, :work_periods, :adjustments] }])
and
Timecard.includes(weeks: [{ days: [:sub_totals, :work_periods, :adjustments] }])
should now eager load and limit the query to just six db hits.