]> source.dussan.org Git - redmine.git/commitdiff
fix always new lft and rgt are lft = 1, rgt = 2 (#6579)
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 26 Mar 2014 01:47:48 +0000 (01:47 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 26 Mar 2014 01:47:48 +0000 (01:47 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13009 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb
test/test_helper.rb

index 0c4b9133ce8b2ac6d66dcea9331b360704879294..5a98caa158ec4103383382c8eda387ff2769f1a4 100644 (file)
@@ -1287,9 +1287,7 @@ class Issue < ActiveRecord::Base
     if root_id.nil?
       # issue was just created
       self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id)
-      set_default_left_and_right
-      Issue.where(["id = ?", id]).
-        update_all(["root_id = ?, lft = ?, rgt = ?", root_id, lft, rgt])
+      Issue.where(["id = ?", id]).update_all(["root_id = ?", root_id])
       if @parent_issue
         move_to_child_of(@parent_issue)
       end
index c831c48fcd2d55871ba7e0765088b2cc61f28a74..259de5a08730c64ad6ffed9bd058f0d418c41581 100644 (file)
@@ -540,7 +540,9 @@ module CollectiveIdea #:nodoc:
 
         # on creation, set automatically lft and rgt to the end of the tree
         def set_default_left_and_right
-          highest_right_row = nested_set_scope(:order => "#{quoted_right_column_full_name} desc").limit(1).lock(true).first
+          highest_right_row =
+            self.class.base_class.unscoped.
+              order("#{quoted_right_column_full_name} desc").limit(1).lock(true).first
           maxright = highest_right_row ? (highest_right_row[right_column_name] || 0) : 0
           # adds the new node to the right of all existing nodes
           self[left_column_name] = maxright + 1
index bc1a350a2d9393eef16abe1e727edb186172be11..14f2d003f70d2de67d456ea14178a63153535b21 100644 (file)
@@ -221,7 +221,8 @@ class ActiveSupport::TestCase
   # It seems correct behavior because of this line comment.
   #   https://github.com/collectiveidea/awesome_nested_set/blame/199fca9bb9/lib/awesome_nested_set/model.rb#L278
   def new_issue_lft
-    ::AwesomeNestedSet::VERSION > "2.1.6" ? Issue.maximum(:rgt) + 1 : 1
+    # ::AwesomeNestedSet::VERSION > "2.1.6" ? Issue.maximum(:rgt) + 1 : 1
+    Issue.maximum(:rgt) + 1
   end
 end