So i have a top level class for Topics, and each can have sub-topics through a parent_id
belongs_to :parent, :class_name => "Topic"
has_many :sub_topics, :class_name => "Topic", :foreign_key => "parent_id"
Each topic has channels...
has_many :channels
But this only gets the direct children.... and I've been struggling with a neat way to get all the channels that are decedents of a topic... including level 2, 3, 4, etc.....
has_many :sub_channels, :through => :sub_topics, source: :channels
This gets the second level channels, but ignores the top level and deeper levels... but this seems to be going down the wrong road for what I'm trying to attain...
Is there a good web resource that explains how to do this?
Have spent quite a bit of time looking into this... seems the best way to go is to use one of the gems like nested set / ancestry to save having to build a lot of queries yourself. Thanks to the commenters above for the reco.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments