1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-22 16:31:12 +00:00

Update enumeration ovverides with their parents (#19657).

git-svn-id: http://svn.redmine.org/redmine/trunk@14634 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2015-09-30 21:07:47 +00:00
parent 8eb1e94f4d
commit 0dcbd13d01

View File

@ -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