Defect #25141

Changing the scope and resetting the position of an acts_as_positioned object inserts it at the one-before-last position

Added by Felix Schäfer over 5 years ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:


Target version:-
Resolution: Affected version:


We have a model where objects should be appended to the list in the new scope when the list scope of the object is changed. We do this by setting the self.position = nil before it is saved, unfortunately this inserts the object at the one-before-last position.

The following patch solves this problem:

diff --git a/lib/redmine/acts/positioned.rb b/lib/redmine/acts/positioned.rb
index 75041fe38..d3959a335 100644
--- a/lib/redmine/acts/positioned.rb
+++ b/lib/redmine/acts/positioned.rb
@@ -67,7 +67,7 @@ module Redmine

         def set_default_position
           if position.nil?
-            self.position = position_scope.maximum(:position).to_i + (new_record? ? 1 : 0)
+            self.position = position_scope.maximum(:position).to_i + ((new_record? || position_scope_changed?) ? 1 : 0)

This affects trunk.

Also available in: Atom PDF