diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-10 06:19:50 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-10 06:19:50 +0000 |
commit | b84a7beb98a1bfe384e92d7c301db0ee30cbf1b6 (patch) | |
tree | 289ee3897ba72bd1cd45aaed9bac774e89d2ac4d /activerecord/lib/active_record | |
parent | adba18106081f55f2e8761b5104d295cacd6a8c6 (diff) | |
download | rails-b84a7beb98a1bfe384e92d7c301db0ee30cbf1b6.tar.gz rails-b84a7beb98a1bfe384e92d7c301db0ee30cbf1b6.tar.bz2 rails-b84a7beb98a1bfe384e92d7c301db0ee30cbf1b6.zip |
acts_as_list plays nicely with inheritance by remembering the class which declared it. Closes #2811.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2964 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/acts/list.rb | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/acts/list.rb b/activerecord/lib/active_record/acts/list.rb index 551c41fb6a..560c74dfff 100644 --- a/activerecord/lib/active_record/acts/list.rb +++ b/activerecord/lib/active_record/acts/list.rb @@ -54,6 +54,10 @@ module ActiveRecord class_eval <<-EOV include ActiveRecord::Acts::List::InstanceMethods + def acts_as_list_class + #{self.name} + end + def position_column '#{configuration[:column]}' end @@ -78,7 +82,7 @@ module ActiveRecord def move_lower return unless lower_item - self.class.transaction do + acts_as_list_class.transaction do lower_item.decrement_position increment_position end @@ -87,7 +91,7 @@ module ActiveRecord def move_higher return unless higher_item - self.class.transaction do + acts_as_list_class.transaction do higher_item.increment_position decrement_position end @@ -95,7 +99,7 @@ module ActiveRecord def move_to_bottom return unless in_list? - self.class.transaction do + acts_as_list_class.transaction do decrement_positions_on_lower_items assume_bottom_position end @@ -103,7 +107,7 @@ module ActiveRecord def move_to_top return unless in_list? - self.class.transaction do + acts_as_list_class.transaction do increment_positions_on_higher_items assume_top_position end @@ -135,14 +139,14 @@ module ActiveRecord def higher_item return nil unless in_list? - self.class.find(:first, :conditions => + acts_as_list_class.find(:first, :conditions => "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" ) end def lower_item return nil unless in_list? - self.class.find(:first, :conditions => + acts_as_list_class.find(:first, :conditions => "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" ) end @@ -171,7 +175,7 @@ module ActiveRecord 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") + acts_as_list_class.find(:first, :conditions => conditions, :order => "#{position_column} DESC") end def assume_bottom_position @@ -184,7 +188,7 @@ module ActiveRecord # This has the effect of moving all the higher items up one. def decrement_positions_on_higher_items(position) - self.class.update_all( + acts_as_list_class.update_all( "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} <= #{position}" ) end @@ -192,7 +196,7 @@ module ActiveRecord # This has the effect of moving all the lower items up one. def decrement_positions_on_lower_items return unless in_list? - self.class.update_all( + acts_as_list_class.update_all( "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}" ) end @@ -200,20 +204,20 @@ module ActiveRecord # This has the effect of moving all the higher items down one. def increment_positions_on_higher_items return unless in_list? - self.class.update_all( + acts_as_list_class.update_all( "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column).to_i}" ) end # This has the effect of moving all the lower items down one. def increment_positions_on_lower_items(position) - self.class.update_all( + acts_as_list_class.update_all( "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} >= #{position}" ) end def increment_positions_on_all_items - self.class.update_all( + acts_as_list_class.update_all( "#{position_column} = (#{position_column} + 1)", "#{scope_condition}" ) end |