Rails4: replace deprecated Relation#update_all at acts_as_list

git-svn-id: http://svn.redmine.org/redmine/trunk@12504 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2014-01-08 04:13:18 +00:00
parent 6dcfa742fd
commit 76110407b7
1 changed files with 15 additions and 15 deletions

View File

@ -233,39 +233,39 @@ module ActiveRecord
# This has the effect of moving all the higher items up one.
def decrement_positions_on_higher_items(position)
acts_as_list_class.update_all(
"#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} <= #{position}"
)
acts_as_list_class.
where("#{scope_condition} AND #{position_column} <= #{position}").
update_all("#{position_column} = (#{position_column} - 1)")
end
# This has the effect of moving all the lower items up one.
def decrement_positions_on_lower_items
return unless in_list?
acts_as_list_class.update_all(
"#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}"
)
acts_as_list_class.
where("#{scope_condition} AND #{position_column} > #{send(position_column).to_i}").
update_all("#{position_column} = (#{position_column} - 1)")
end
# This has the effect of moving all the higher items down one.
def increment_positions_on_higher_items
return unless in_list?
acts_as_list_class.update_all(
"#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column).to_i}"
)
acts_as_list_class.
where("#{scope_condition} AND #{position_column} < #{send(position_column).to_i}").
update_all("#{position_column} = (#{position_column} + 1)")
end
# This has the effect of moving all the lower items down one.
def increment_positions_on_lower_items(position)
acts_as_list_class.update_all(
"#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} >= #{position}"
)
acts_as_list_class.
where("#{scope_condition} AND #{position_column} >= #{position}").
update_all("#{position_column} = (#{position_column} + 1)")
end
# Increments position (<tt>position_column</tt>) of all items in the list.
def increment_positions_on_all_items
acts_as_list_class.update_all(
"#{position_column} = (#{position_column} + 1)", "#{scope_condition}"
)
acts_as_list_class.
where("#{scope_condition}").
update_all("#{position_column} = (#{position_column} + 1)")
end
def insert_at_position(position)