mirror of
https://github.com/redmine/redmine.git
synced 2026-05-07 12:36:38 +02:00
Adds :order option to acts_as_nested_tree so that children are sorted alphabetically when the tree is rebuilt.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/work@2156 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -56,6 +56,7 @@ module CollectiveIdea #:nodoc:
|
||||
:parent_column => 'parent_id',
|
||||
:left_column => 'lft',
|
||||
:right_column => 'rgt',
|
||||
:order => 'id',
|
||||
:dependent => :delete_all, # or :destroy
|
||||
}.merge(options)
|
||||
|
||||
@@ -179,14 +180,14 @@ module CollectiveIdea #:nodoc:
|
||||
# set left
|
||||
node[left_column_name] = indices[scope.call(node)] += 1
|
||||
# find
|
||||
find(:all, :conditions => ["#{quoted_parent_column_name} = ? #{scope.call(node)}", node], :order => "#{quoted_left_column_name}, #{quoted_right_column_name}, id").each{|n| set_left_and_rights.call(n) }
|
||||
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) }
|
||||
# set right
|
||||
node[right_column_name] = indices[scope.call(node)] += 1
|
||||
node.save!
|
||||
end
|
||||
|
||||
# Find root node(s)
|
||||
root_nodes = find(:all, :conditions => "#{quoted_parent_column_name} IS NULL", :order => "#{quoted_left_column_name}, #{quoted_right_column_name}, id").each do |root_node|
|
||||
root_nodes = find(:all, :conditions => "#{quoted_parent_column_name} IS NULL", :order => "#{quoted_left_column_name}, #{quoted_right_column_name}, #{acts_as_nested_set_options[:order]}").each do |root_node|
|
||||
# setup index for this scope
|
||||
indices[scope.call(root_node)] ||= 0
|
||||
set_left_and_rights.call(root_node)
|
||||
|
||||
Reference in New Issue
Block a user