Permalink
Browse files

Wrapped multi-step operations in transactions

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@155 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 647c5e0 commit 0a8f382b80efcaf26e2f3a432d07c137b72dd0d3 @dhh dhh committed Dec 14, 2004
Showing with 22 additions and 16 deletions.
  1. +22 −16 activerecord/lib/active_record/mixins/list.rb
@@ -37,24 +37,34 @@ def self.append_features(base)
def move_lower
return unless lower_item
- lower_item.decrement_position
- increment_position
+
+ self.class.transaction do
+ lower_item.decrement_position
+ increment_position
+ end
end
def move_higher
return unless higher_item
- higher_item.increment_position
- decrement_position
+
+ self.class.transaction do
+ higher_item.increment_position
+ decrement_position
+ end
end
def move_to_bottom
- decrement_positions_on_lower_items
- assume_bottom_position
+ self.class.transaction do
+ decrement_positions_on_lower_items
+ assume_bottom_position
+ end
end
def move_to_top
- increment_positions_on_higher_items
- assume_top_position
+ self.class.transaction do
+ increment_positions_on_higher_items
+ assume_top_position
+ end
end
@@ -76,13 +86,11 @@ def remove_from_list
# Changing the position
def increment_position
- self.position = position.to_i + 1
- save
+ update_attribute "position", position.to_i + 1
end
def decrement_position
- self.position = position.to_i - 1
- save
+ update_attribute "position", position.to_i - 1
end
@@ -125,13 +133,11 @@ def bottom_item
end
def assume_bottom_position
- self.position = bottom_position_in_list.to_i + 1
- save
+ update_attribute "position", bottom_position_in_list.to_i + 1
end
def assume_top_position
- self.position = 1
- save
+ update_attribute "position", 1
end
def decrement_positions_on_lower_items

0 comments on commit 0a8f382

Please sign in to comment.