title: Nested relationships within Join Tables - Rails
body: <p>I'm rather new to Rails and have a question about how to successfully add sub-categories to an existing Join Table relationship.</p>
  
  <p>For example, assume I'm building a job board. Each job has 5 major filter categories ( <code>Job_Type [General Management, Finance &amp; Operations, etc.]</code>, <code>Industry [ Technology, Healthcare, etc.]</code>, <code>Region [Northwest, Southeast, etc.]</code>, and so on ). I want each of those to have subcategories as well ( ex. This job post has a <code>Region &gt; Southeast &gt; South Carolina &gt; Greenville</code> ).</p>
  
  <p>Setting up an initial Join Table association for the 5 major filter types made sense for future filtering and searchability.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is my current <code>Posting</code> Model</p>
  
  <pre><code>class Posting &lt; ActiveRecord::Base
    mount_uploader :avatar, AvatarUploader
  
    belongs_to :recruiter, class_name: "User"
    belongs_to :company
    has_many :interests
    has_many :comments, as: :commentable
    has_and_belongs_to_many :job_types
    has_and_belongs_to_many :industries
    has_and_belongs_to_many :regions
    has_and_belongs_to_many :market_caps
    has_and_belongs_to_many :ownerships
    has_many :users, through: :interests
    acts_as_followable
  end
  </code></pre>
  
  <p>I'm currently using join tables instead of an array directly on the ActiveRecord for speed sake and for filtering/searching capabilities later on. It also allows me to use these join table in conjunction with a plethora of other necessary ActiveRecord associations.</p>
  
  <p>Here is a snippet of what <code>job_type</code> looks like:</p>
  
  <pre><code>class JobType &lt; ActiveRecord::Base
    has_and_belongs_to_many :postings
    has_and_belongs_to_many :news_items
    has_and_belongs_to_many :companies
    has_and_belongs_to_many :users
    has_and_belongs_to_many :mkt_ints
  end
  </code></pre>
  
  <p>This allows me access to a simple array of associated models, but I'm confused as to how to move past that to an array of arrays with potential further nested arrays. It feels clunky to add additional join tables for the first join tables. I'm sure there's a better solution and would love to get any insight you might have.</p>
  
  <p><strong>SECOND EDIT</strong></p>
  
  <p>Here's a representational picture of what I am trying to do if it helps.</p>
  
  <p><a href="https://i.stack.imgur.com/JOZDX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JOZDX.png" alt="enter image description here"></a></p>
  
  <p>Thanks!</p>