Browse files

Merge branch 'patch-1' of github.com:aepstein/acts_as_list into patch-1

  • Loading branch information...
2 parents 4765b2f + 1b9072f commit a8ef871532c74bf012533d4b0331559acb5abb4e @aepstein committed Oct 30, 2011
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/acts_as_list/active_record/acts/list.rb
View
8 lib/acts_as_list/active_record/acts/list.rb
@@ -243,10 +243,11 @@ def decrement_positions_on_higher_items(position)
end
# This has the effect of moving all the lower items up one.
- def decrement_positions_on_lower_items
+ def decrement_positions_on_lower_items(position=nil)
return unless in_list?
+ position ||= send(position_column).to_i
acts_as_list_class.update_all(
- "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}"
+ "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{position}"
)
end
@@ -281,8 +282,9 @@ def insert_at_position(position)
# used by insert_at_position instead of remove_from_list, as postgresql raises error if position_column has non-null constraint
def store_at_0
if in_list?
- decrement_positions_on_lower_items
+ old_position = send(position_column).to_i
update_attribute(position_column, 0)
+ decrement_positions_on_lower_items(old_position)
end
end
end

0 comments on commit a8ef871

Please sign in to comment.