diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-14 18:17:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-14 18:17:44 +0000 |
commit | 0a8f382b80efcaf26e2f3a432d07c137b72dd0d3 (patch) | |
tree | ee2d0fc04995b52de58982eb3752d19596208d77 /activerecord/lib/active_record | |
parent | 647c5e05658562b88b324722b83e9aa0dc87d66f (diff) | |
download | rails-0a8f382b80efcaf26e2f3a432d07c137b72dd0d3.tar.gz rails-0a8f382b80efcaf26e2f3a432d07c137b72dd0d3.tar.bz2 rails-0a8f382b80efcaf26e2f3a432d07c137b72dd0d3.zip |
Wrapped multi-step operations in transactions
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@155 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/mixins/list.rb | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/mixins/list.rb b/activerecord/lib/active_record/mixins/list.rb index d0efb02396..6910ac771f 100644 --- a/activerecord/lib/active_record/mixins/list.rb +++ b/activerecord/lib/active_record/mixins/list.rb @@ -37,24 +37,34 @@ module ActiveRecord 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 @@ module ActiveRecord # 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 @@ module ActiveRecord 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 |