forked from refinery/refinerycms
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manually preload the :translations to avoid the N+1 queries.
- Loading branch information
1 parent
332b512
commit 3e2b3ad
Showing
2 changed files
with
13 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
module Refinery | ||
module Admin | ||
module PagesHelper | ||
def parent_id_nested_set_options(current_page) | ||
all_pages = [] | ||
options = nested_set_options(::Refinery::Page, current_page) do |page| | ||
all_pages << page | ||
page | ||
end | ||
# page.title needs the :translations association, doing something like | ||
# nested_set_options(::Refinery::Page.includes(:translations), page) doesn't work | ||
ActiveRecord::Associations::Preloader.new(all_pages, :translations).run | ||
options.map! {|page, id| ["#{'-' * page.level} #{page.title}", id]} | ||
options | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters