apply Redmine awesome_nested_set 2.1.5 modification

git-svn-id: http://svn.redmine.org/redmine/trunk@12679 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2014-01-20 05:59:50 +00:00
parent 90777c1673
commit bcec29d5e4
1 changed files with 7 additions and 3 deletions

View File

@ -198,14 +198,17 @@ 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
where(["#{quoted_parent_column_full_name} = ? #{scope.call(node)}", node]).order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, id").each{|n| set_left_and_rights.call(n) } where(["#{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!(:validate => validate_nodes) node.save!(:validate => validate_nodes)
end end
# Find root node(s) # Find root node(s)
root_nodes = where("#{quoted_parent_column_full_name} IS NULL").order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, id").each do |root_node| root_nodes = where("#{quoted_parent_column_name} IS NULL").
order(acts_as_nested_set_options[:order]).each do |root_node|
# setup index for this scope # setup index for this scope
indices[scope.call(root_node)] ||= 0 indices[scope.call(root_node)] ||= 0
set_left_and_rights.call(root_node) set_left_and_rights.call(root_node)
@ -307,7 +310,7 @@ module CollectiveIdea #:nodoc:
# Returns true if this is the end of a branch. # Returns true if this is the end of a branch.
def leaf? def leaf?
persisted? && right.to_i - left.to_i == 1 new_record? || (persisted? && right.to_i - left.to_i == 1)
end end
# Returns true is this is a child node # Returns true is this is a child node
@ -590,6 +593,7 @@ module CollectiveIdea #:nodoc:
["#{quoted_right_column_name} = (#{quoted_right_column_name} - ?)", diff] ["#{quoted_right_column_name} = (#{quoted_right_column_name} - ?)", diff]
) )
reload
# Don't allow multiple calls to destroy to corrupt the set # Don't allow multiple calls to destroy to corrupt the set
self.skip_before_destroy = true self.skip_before_destroy = true
end end