Finding Listings that Belong to Categories

I have two models that are playing nicely together. The first is the
Category model that uses acts_as_tree to create a hierarchy of
categories based on parent_id. Example:

Category 1
Sub 1
Sub 2
Subsub 1
Subsubsub 1
Subsub 2
Sub 3
Category 2
Category 3

Etc…

The second is a Listings model that has a many-to-many relationship to
the Categories model using has_many :through

So here’s my question: How would I go about finding all of the
listings in “Sub 2” AND below?

Doing a find for the listings that belong to Sub 2 is obviously very
easy, but what about including subsub 1, subsubsub1, and subsub 2 and
returning all tof the results in one instance object (like
@listings)?

Any general idea of how to go about this would be helpful. I’m pretty
new at this so I hope i’m clear enough in my explanation. Thanks!

recreant wrote:

Sub 3

Doing a find for the listings that belong to Sub 2 is obviously very
easy, but what about including subsub 1, subsubsub1, and subsub 2 and
returning all tof the results in one instance object (like
@listings)?

Any general idea of how to go about this would be helpful. I’m pretty
new at this so I hope i’m clear enough in my explanation. Thanks!

You should add nested-set capability to the model:
GitHub - chris/better_nested_set: better_nested_set Rails plugin (my fork from official SVN)
GitHub - collectiveidea/awesome_nested_set: An awesome replacement for acts_as_nested_set and better_nested_set.


Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com