ruby - Rails 3 - Eager loading on a legacy database -


I've found a web app with the following tables: Categories, sub-categories, and Pages. Pages have category_id and sub_category_id columns

I have to write an efficient question for curious load pages according to the category and sub-category for the order sorted in my view (Crude example is as follows):

  - Category one (categories | Category | ...) - Page one (category.pages.each do | page | ...) - sub-category forest (category.secategory.each do | Sub_category | ... ---- Page To (Sub_category.pages.each do | page | ...)  

category .rb:

  Category Category & active; Active Urd :: Base is has_many: pages have has_many: sub_categories end  

sub-category. Rb:

  class sub-category: active record: base is_to : Category has_many: pages end  

  class page & lt; ActiveRecord :: base is_to: range belongs_to: sub_category scope: active_pages, : Conditions = & gt; {: is_active = & gt; true} end  

I have experimented with questions with small success like the following, where the sub-provisions are concerned: < / P>

  Categ Ory.includes (: subcategories, pages) .where ('pages.is_active = 1')  < / Pre> 

Categories work great, but I'm not sure how to load curiosities eagerly. Thanks in advance, any help greatly appreciate.

According to which I was just looking at something like this what you would like to do: / P>

  category.fund (: all ,: included => gt: [: page, {: sub_categories =>; pages}])  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -