collectiveidea/awesome_nested_set — pull request #243 by szTheory (2014-04-03 21:45:04+00:00)
Title: Fix #rebuild! (was rebuilding root nodes but not children)

It was only rebuilding lft/rgt for root nodes, not children. Caused by AR not substituting `node` for its primary key in the generated SQL. See below:

[2] pry(Department)> find(:all, :conditions => ["#{quoted_parent_column_name} = ? #{scope.call(node)}", node], :order => "#{quoted_left_column_name}, #{quoted_right_column_name}, id")
Company Load (0.9ms) SELECT "companies".* FROM "companies" WHERE ("companies"."id" = 43)
Department Load (0.6ms) SELECT "departments".* FROM "departments" WHERE ("parent_id" = NULL AND "company_id" = 43 ) AND ("departments".company_id = 43) ORDER BY "lft", "rgt", id
=> []
[3] pry(Department)> node
=> #