class Channel < ActiveRecord::Base
has_many :programs
end
class Program < ActiveRecord::Base
belongs_to :channel
has_many :program_schedules
end
class ProgramSchedule < ActiveRecord::Base
belongs_to :program
end
I would want to get an array of data like this:
-
Channel 1:
-
Program 1
- Schedule 1
-
Program 2
- Schedule 1
- Schedule 2
- Schedule 3
-
-
Channel 2:
- Program 1
- Schedule 1
- Schedule 2
- Schedule 3
- Program 1
I have tried with this query, but it retrieve only “channel”-rows (without Programs and Schedules)
@data = Channel.joins(:programs => :program_schedules).group("channel_id")
I would not recommend you to get all rows this way.
Do something like this.
In your controller, say in index action
In the view where you want to show everything.