I’m trying to wrap my caffeine soaked brain around has_many :through
following along at:
I think my models are a little more complex than what fits this
I have a directory of members, each member can belong to multiple
The category table references itself to build a category list, joined
with parent_id. Top level categories will not have members, only
ie. Finance is top level (no member associated). Accountants, financial
advisors, investors will be subcategories (with lots of members).
I’m using a join table between members and categories to build the
associations between members and the category.
class MemberToCategory < ActiveRecord::Base
class MemberType < ActiveRecord::Base
has_many :members, :through => :member_to_categories
class Member < ActiveRecord::Base
has_many :member_types, :through => :member_to_categories
My problem is two-fold.
- When the visitor selects a top level category, I need to pull all
members of all of the related subcategories.
- When a subcategory is selected, I only need to pull the members who
belong to that subcategory only.
My Category table:
my member_to_categories table:
Any help will be greatly appreciated!