##// END OF EJS Templates
fix always new lft and rgt are lft = 1, rgt = 2 (#6579)...
Toshi MARUYAMA -
r12734:3c83d1c64640
parent child
Show More
@@ -1287,9 +1287,7 class Issue < ActiveRecord::Base
1287 if root_id.nil?
1287 if root_id.nil?
1288 # issue was just created
1288 # issue was just created
1289 self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id)
1289 self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id)
1290 set_default_left_and_right
1290 Issue.where(["id = ?", id]).update_all(["root_id = ?", root_id])
1291 Issue.where(["id = ?", id]).
1292 update_all(["root_id = ?, lft = ?, rgt = ?", root_id, lft, rgt])
1293 if @parent_issue
1291 if @parent_issue
1294 move_to_child_of(@parent_issue)
1292 move_to_child_of(@parent_issue)
1295 end
1293 end
@@ -540,7 +540,9 module CollectiveIdea #:nodoc:
540
540
541 # on creation, set automatically lft and rgt to the end of the tree
541 # on creation, set automatically lft and rgt to the end of the tree
542 def set_default_left_and_right
542 def set_default_left_and_right
543 highest_right_row = nested_set_scope(:order => "#{quoted_right_column_full_name} desc").limit(1).lock(true).first
543 highest_right_row =
544 self.class.base_class.unscoped.
545 order("#{quoted_right_column_full_name} desc").limit(1).lock(true).first
544 maxright = highest_right_row ? (highest_right_row[right_column_name] || 0) : 0
546 maxright = highest_right_row ? (highest_right_row[right_column_name] || 0) : 0
545 # adds the new node to the right of all existing nodes
547 # adds the new node to the right of all existing nodes
546 self[left_column_name] = maxright + 1
548 self[left_column_name] = maxright + 1
@@ -221,7 +221,8 class ActiveSupport::TestCase
221 # It seems correct behavior because of this line comment.
221 # It seems correct behavior because of this line comment.
222 # https://github.com/collectiveidea/awesome_nested_set/blame/199fca9bb9/lib/awesome_nested_set/model.rb#L278
222 # https://github.com/collectiveidea/awesome_nested_set/blame/199fca9bb9/lib/awesome_nested_set/model.rb#L278
223 def new_issue_lft
223 def new_issue_lft
224 ::AwesomeNestedSet::VERSION > "2.1.6" ? Issue.maximum(:rgt) + 1 : 1
224 # ::AwesomeNestedSet::VERSION > "2.1.6" ? Issue.maximum(:rgt) + 1 : 1
225 Issue.maximum(:rgt) + 1
225 end
226 end
226 end
227 end
227
228
General Comments 0
You need to be logged in to leave comments. Login now