Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8729029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:45:32+00:00 2026-06-13T08:45:32+00:00

class Channel < ActiveRecord::Base has_many :programs end class Program < ActiveRecord::Base belongs_to :channel has_many

  • 0
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

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")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:45:34+00:00Added an answer on June 13, 2026 at 8:45 am

    I would not recommend you to get all rows this way.

    Do something like this.

    In your controller, say in index action

    def index
      @channels = Channel.all
    end
    

    In the view where you want to show everything.

    %ul#channels
      = @channels.each do |channel|
        %li= channel.name
        %ul.channel
          = channel.programs.each do |program|
            %li= program.name
            %ul.program
              = program.schedules.each do |schedule|
                %li= schedule.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class A attr_accessor :dab .... end Now I have an array of instances of
I used ActiveRecord::Base.set_table_name to set my table name on a dynamically created ActiveRecord class.
in my web.xml <servlet> <servlet-name>channelConnected</servlet-name> <servlet-class>ChannelConnected</servlet-class> </servlet> <servlet-mapping> <servlet-name>channelConnected</servlet-name> <url-pattern>/_ah/channel/connected</url-pattern> </servlet-mapping> my servlet public
I've got a class like this: [XmlRoot(channel)] public class Channel { [XmlElement(title)] public String
I have these classe where items (class Item) is related to channel object: channel_items
ItemsByGuid definition: private Dictionary<string, Channel> ItemsByGuid = new Dictionary<string, Channel>(); i have a class:
My setup The following all works fine: RKManagedObjectMapping* chanMapping = [RKManagedObjectMapping mappingForClass:[Channel class] inManagedObjectStore:objectStore];
My java code looks like this: class xHandler { private Channel _channel; // Methods...
I have the following two database model: class UserProfile(models.Model): description = models.TextField() class Channel(models.Model):
I have the following HTML: <ul> <li> <p class=channel-show-time>Test 1</p> </li> <li> <p class=channel-show-time>Test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.