あなたはhas_and_belongs_to_many
ここで関係を望んでいます:
has_and_belongs_to_many :child_categories, class_name: "Category", inverse_of: :parent_categories
has_and_belongs_to_many :parent_categories, class_name: "Catgeory", inverse_of: child_categories
ユースケース:
film_category1 = Category.create(name: "French")
film_category2 = Category.create(name: "Spanish")
film_category3 = Category.create(name: "Romantic")
film_category1.child_categories << film_category3
film_category2.child_categories << film_category3
film_category3.parent_categories # [film_category1, film_category2]
film_category2.child_categories # [film_category3]
等