diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/acts/list.rb | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/acts/list.rb b/activerecord/lib/active_record/acts/list.rb index 626547f005..e8f7f64db1 100644 --- a/activerecord/lib/active_record/acts/list.rb +++ b/activerecord/lib/active_record/acts/list.rb @@ -109,6 +109,18 @@ module ActiveRecord def last? self.send(position_column) == bottom_position_in_list end + + def higher_item + self.class.find_first( + "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" + ) + end + + def lower_item + self.class.find_first( + "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" + ) + end private @@ -123,18 +135,6 @@ module ActiveRecord # Overwrite this method to define the scope of the list changes def scope_condition() "1" end - def higher_item - self.class.find_first( - "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" - ) - end - - def lower_item - self.class.find_first( - "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" - ) - end - def bottom_position_in_list item = bottom_item item ? item.send(position_column) : 0 @@ -163,7 +163,7 @@ module ActiveRecord def increment_positions_on_higher_items self.class.update_all( - "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column)}" + "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column).to_i}" ) end |