diff options
author | Jamis Buck <jamis@37signals.com> | 2005-07-20 12:47:55 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-07-20 12:47:55 +0000 |
commit | d886ad5c8b6f9eaa8b82e634c989aee48ccaf240 (patch) | |
tree | 5dddadb2d4c751e46f60517b658407e243364500 /activerecord/lib | |
parent | 7077d8bb3d71742d5130753816508ccf302d7b26 (diff) | |
download | rails-d886ad5c8b6f9eaa8b82e634c989aee48ccaf240.tar.gz rails-d886ad5c8b6f9eaa8b82e634c989aee48ccaf240.tar.bz2 rails-d886ad5c8b6f9eaa8b82e634c989aee48ccaf240.zip |
Fix acts_as_list such that moving next-to-last item to the bottom does not result in duplicate positions
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1872 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/acts/list.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/acts/list.rb b/activerecord/lib/active_record/acts/list.rb index 29b5a0a58e..f3cb3496d8 100644 --- a/activerecord/lib/active_record/acts/list.rb +++ b/activerecord/lib/active_record/acts/list.rb @@ -163,17 +163,19 @@ module ActiveRecord # Overwrite this method to define the scope of the list changes def scope_condition() "1" end - def bottom_position_in_list - item = bottom_item + def bottom_position_in_list(except = nil) + item = bottom_item(except) item ? item.send(position_column) : 0 end - def bottom_item - self.class.find(:first, :conditions => scope_condition, :order => "#{position_column} DESC") + def bottom_item(except = nil) + conditions = scope_condition + conditions = "#{conditions} AND id != #{except.id}" if except + self.class.find(:first, :conditions => conditions, :order => "#{position_column} DESC") end def assume_bottom_position - update_attribute(position_column, bottom_position_in_list.to_i + 1) unless last? + update_attribute(position_column, bottom_position_in_list(self).to_i + 1) end def assume_top_position |