Skip to content

Commit

Permalink
Rather than mapping in memory we can use ARel to select the Page::Tra…
Browse files Browse the repository at this point in the history
…nslation#page_id column and make Page think it's the Page#id (which it is).
  • Loading branch information
parndt committed Apr 8, 2011
1 parent 191d8d5 commit f0b67a8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pages/app/models/page.rb
Expand Up @@ -57,7 +57,7 @@ def translation

scope :live, where(:draft => false)
scope :by_title, lambda {|t|
where(:id => Page::Translation.where(:locale => Globalize.locale, :title => t).map(&:page_id))
where(:id => Page::Translation.where(:locale => Globalize.locale, :title => t).select('page_id AS id'))
}

# Shows all pages with :show_in_menu set to true, but it also
Expand All @@ -66,7 +66,7 @@ def translation
# using all of the page_ids we further filter against this model's table.
scope :in_menu, lambda {
where(:show_in_menu => true).includes(:translations).where(
:id => Page::Translation.where(:locale => Globalize.locale).map(&:page_id)
:id => Page::Translation.where(:locale => Globalize.locale).select('page_id AS id')
)
}

Expand Down

0 comments on commit f0b67a8

Please sign in to comment.