Commit 185e9e33 authored by Enrique García Cota's avatar Enrique García Cota

modifications on awesome_nested_set according to this post:…

modifications on awesome_nested_set according to this post: https://www.chiliproject.org/boards/2/topics/314
parent 86751132
...@@ -165,7 +165,7 @@ module CollectiveIdea #:nodoc: ...@@ -165,7 +165,7 @@ module CollectiveIdea #:nodoc:
# Rebuilds the left & rights if unset or invalid. Also very useful for converting from acts_as_tree. # Rebuilds the left & rights if unset or invalid. Also very useful for converting from acts_as_tree.
def rebuild! def rebuild!
# Don't rebuild a valid tree. # Don't rebuild a valid tree.
return true if valid? # return true if valid?
scope = lambda{|node|} scope = lambda{|node|}
if acts_as_nested_set_options[:scope] if acts_as_nested_set_options[:scope]
...@@ -181,7 +181,7 @@ module CollectiveIdea #:nodoc: ...@@ -181,7 +181,7 @@ module CollectiveIdea #:nodoc:
# set left # set left
node[left_column_name] = indices[scope.call(node)] += 1 node[left_column_name] = indices[scope.call(node)] += 1
# find # find
find(:all, :conditions => ["#{quoted_parent_column_name} = ? #{scope.call(node)}", node], :order => "#{quoted_left_column_name}, #{quoted_right_column_name}, #{acts_as_nested_set_options[:order]}").each{|n| set_left_and_rights.call(n) } find(:all, :conditions => ["#{quoted_parent_column_name} = ? #{scope.call(node)}", node], :order => "#{acts_as_nested_set_options[:order]}").each{|n| set_left_and_rights.call(n) }
# set right # set right
node[right_column_name] = indices[scope.call(node)] += 1 node[right_column_name] = indices[scope.call(node)] += 1
node.save! node.save!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment