summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-09-30 21:07:47 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-09-30 21:07:47 +0000
commit0dcbd13d017c23f1e1cf0e9b46dc81183235ba6b (patch)
tree1d1538a650f28ef1cfc1d61cb97da3c75878d3f6
parent8eb1e94f4d18a8e3d268392aa518b039dbc749c0 (diff)
downloadredmine-0dcbd13d017c23f1e1cf0e9b46dc81183235ba6b.tar.gz
redmine-0dcbd13d017c23f1e1cf0e9b46dc81183235ba6b.zip
Update enumeration ovverides with their parents (#19657).
git-svn-id: http://svn.redmine.org/redmine/trunk@14634 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/enumeration.rb11
1 files changed, 3 insertions, 8 deletions
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index 2ec96dc1f..b2337fa88 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -132,14 +132,9 @@ class Enumeration < ActiveRecord::Base
# Overrides acts_as_list reset_positions_in_list so that enumeration overrides
# get the same position as the overriden enumeration
def reset_positions_in_list
- super
- # TODO: no database specific statement
- if Redmine::Database.mysql?
- self.class.connection.execute("UPDATE #{self.class.table_name} c JOIN #{self.class.table_name} p on p.id = c.parent_id SET c.position = p.position")
- else
- self.class.
- where("parent_id IS NOT NULL").
- update_all("position = (SELECT MIN(position) FROM #{self.class.table_name} p WHERE p.id = #{self.class.table_name}.parent_id)")
+ acts_as_list_class.where(scope_condition).reorder("#{position_column} ASC, id ASC").each_with_index do |item, i|
+ acts_as_list_class.where("id = :id OR parent_id = :id", :id => item.id).
+ update_all({position_column => (i + 1)})
end
end