Parent id nested set options #1633

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants
Contributor

thedarkone commented May 2, 2012

Manually preload :translations association to avoid the extra queries.

This pull request passes (merged 868d93d into 21ab29b).

@ugisozols ugisozols commented on an outdated diff May 2, 2012

pages/app/helpers/refinery/admin/pages_helper.rb
@@ -1,6 +1,14 @@
module Refinery
module Admin
module PagesHelper
+ def parent_id_nested_set_options(page)
+ pages = []
+ nested_set_options(::Refinery::Page, page) {|i| pages << i}
+ # page.title needs the :translations association, doing something like
+ # nested_set_options(::Refinery::Page.includes(:translations), page) doesn't work
+ ActiveRecord::Associations::Preloader.new(pages, :translations).run
+ pages.map {|i, id| ["#{'-' * i.level} #{i.title}", id]}
@ugisozols

ugisozols May 2, 2012

Owner

i is the instance of page and id is nil so this produces select tree with empty values for options. Can you fix it please? Thanks!

Owner

ugisozols commented May 2, 2012

For the future - please open PR's against master branch instead of 2-0-stable. I'm asking this so that we can put new stuff in the dev branch first and only then backport needed changes/fixes to the stable branches. Thanks :)

Owner

ugisozols commented May 2, 2012

Bonus points for specs!

Contributor

thedarkone commented May 2, 2012

Re-pushed, thanks for catching that!

Dev branches and specs are for sissies :).

This pull request passes (merged 3e2b3ad into 21ab29b).

Owner

ugisozols commented May 3, 2012

I liked first version better because it was shorter and cleaner. All you had to do was to remove id. i already was an instance of page so you had access to page id. WDYT?

Owner

parndt commented May 12, 2012

Merged. Specs are for people who want to ensure that we don't break your code later ;-)

Owner

parndt commented May 12, 2012

Oh, and I merged it to master and with e4c0aae and c8dabae

Owner

parndt commented May 12, 2012

Opened #1653 for 2-0-stable

parndt closed this May 12, 2012

@ugisozols ugisozols added a commit that referenced this pull request May 12, 2012

@ugisozols ugisozols Merge pull request #1653 from resolve/pull_1633
Replaces #1633
b013343
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment