##// END OF EJS Templates
apply Redmine awesome_nested_set 2.1.5 modification...
Toshi MARUYAMA -
r12404:bcec29d5e42b
parent child
Show More
@@ -198,14 +198,17 module CollectiveIdea #:nodoc:
198 # set left
198 # set left
199 node[left_column_name] = indices[scope.call(node)] += 1
199 node[left_column_name] = indices[scope.call(node)] += 1
200 # find
200 # find
201 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) }
201 where(["#{quoted_parent_column_name} = ? #{scope.call(node)}", node]).
202 order(acts_as_nested_set_options[:order]).
203 each{|n| set_left_and_rights.call(n) }
202 # set right
204 # set right
203 node[right_column_name] = indices[scope.call(node)] += 1
205 node[right_column_name] = indices[scope.call(node)] += 1
204 node.save!(:validate => validate_nodes)
206 node.save!(:validate => validate_nodes)
205 end
207 end
206
208
207 # Find root node(s)
209 # Find root node(s)
208 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|
210 root_nodes = where("#{quoted_parent_column_name} IS NULL").
211 order(acts_as_nested_set_options[:order]).each do |root_node|
209 # setup index for this scope
212 # setup index for this scope
210 indices[scope.call(root_node)] ||= 0
213 indices[scope.call(root_node)] ||= 0
211 set_left_and_rights.call(root_node)
214 set_left_and_rights.call(root_node)
@@ -307,7 +310,7 module CollectiveIdea #:nodoc:
307
310
308 # Returns true if this is the end of a branch.
311 # Returns true if this is the end of a branch.
309 def leaf?
312 def leaf?
310 persisted? && right.to_i - left.to_i == 1
313 new_record? || (persisted? && right.to_i - left.to_i == 1)
311 end
314 end
312
315
313 # Returns true is this is a child node
316 # Returns true is this is a child node
@@ -590,6 +593,7 module CollectiveIdea #:nodoc:
590 ["#{quoted_right_column_name} = (#{quoted_right_column_name} - ?)", diff]
593 ["#{quoted_right_column_name} = (#{quoted_right_column_name} - ?)", diff]
591 )
594 )
592
595
596 reload
593 # Don't allow multiple calls to destroy to corrupt the set
597 # Don't allow multiple calls to destroy to corrupt the set
594 self.skip_before_destroy = true
598 self.skip_before_destroy = true
595 end
599 end
General Comments 0
You need to be logged in to leave comments. Login now