@@ -198,14 +198,17 module CollectiveIdea #:nodoc: | |||
|
198 | 198 | # set left |
|
199 | 199 | node[left_column_name] = indices[scope.call(node)] += 1 |
|
200 | 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 | 204 | # set right |
|
203 | 205 | node[right_column_name] = indices[scope.call(node)] += 1 |
|
204 | 206 | node.save!(:validate => validate_nodes) |
|
205 | 207 | end |
|
206 | 208 | |
|
207 | 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 | 212 | # setup index for this scope |
|
210 | 213 | indices[scope.call(root_node)] ||= 0 |
|
211 | 214 | set_left_and_rights.call(root_node) |
@@ -307,7 +310,7 module CollectiveIdea #:nodoc: | |||
|
307 | 310 | |
|
308 | 311 | # Returns true if this is the end of a branch. |
|
309 | 312 | def leaf? |
|
310 | persisted? && right.to_i - left.to_i == 1 | |
|
313 | new_record? || (persisted? && right.to_i - left.to_i == 1) | |
|
311 | 314 | end |
|
312 | 315 | |
|
313 | 316 | # Returns true is this is a child node |
@@ -590,6 +593,7 module CollectiveIdea #:nodoc: | |||
|
590 | 593 | ["#{quoted_right_column_name} = (#{quoted_right_column_name} - ?)", diff] |
|
591 | 594 | ) |
|
592 | 595 | |
|
596 | reload | |
|
593 | 597 | # Don't allow multiple calls to destroy to corrupt the set |
|
594 | 598 | self.skip_before_destroy = true |
|
595 | 599 | end |
General Comments 0
You need to be logged in to leave comments.
Login now