diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-12 05:33:09 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-01-12 05:33:09 +0000 |
commit | 8d3ff3abc757dee8c6538c1f26f839882786a5cc (patch) | |
tree | 7784271fea307ed5762c1bad32d905c13a7f2629 /activerecord/lib/active_record/acts | |
parent | ef4ac31de3f310c6426a6d9ebc86b4810ac6325b (diff) | |
download | rails-8d3ff3abc757dee8c6538c1f26f839882786a5cc.tar.gz rails-8d3ff3abc757dee8c6538c1f26f839882786a5cc.tar.bz2 rails-8d3ff3abc757dee8c6538c1f26f839882786a5cc.zip |
acts_as_nested_set works with single-table inheritance. Closes #6030.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5889 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/acts')
-rw-r--r-- | activerecord/lib/active_record/acts/nested_set.rb | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/acts/nested_set.rb b/activerecord/lib/active_record/acts/nested_set.rb index 9d5bcf4d3d..09bf1c39af 100644 --- a/activerecord/lib/active_record/acts/nested_set.rb +++ b/activerecord/lib/active_record/acts/nested_set.rb @@ -163,9 +163,9 @@ module ActiveRecord child[left_col_name] = right_bound child[right_col_name] = right_bound + 1 self[right_col_name] += 2 - self.class.transaction { - self.class.update_all( "#{left_col_name} = (#{left_col_name} + 2)", "#{scope_condition} AND #{left_col_name} >= #{right_bound}" ) - self.class.update_all( "#{right_col_name} = (#{right_col_name} + 2)", "#{scope_condition} AND #{right_col_name} >= #{right_bound}" ) + self.class.base_class.transaction { + self.class.base_class.update_all( "#{left_col_name} = (#{left_col_name} + 2)", "#{scope_condition} AND #{left_col_name} >= #{right_bound}" ) + self.class.base_class.update_all( "#{right_col_name} = (#{right_col_name} + 2)", "#{scope_condition} AND #{right_col_name} >= #{right_bound}" ) self.save child.save } @@ -180,17 +180,17 @@ module ActiveRecord # Returns a set of itself and all of its nested children def full_set - self.class.find(:all, :conditions => "#{scope_condition} AND (#{left_col_name} BETWEEN #{self[left_col_name]} and #{self[right_col_name]})" ) + self.class.base_class.find(:all, :conditions => "#{scope_condition} AND (#{left_col_name} BETWEEN #{self[left_col_name]} and #{self[right_col_name]})" ) end # Returns a set of all of its children and nested children def all_children - self.class.find(:all, :conditions => "#{scope_condition} AND (#{left_col_name} > #{self[left_col_name]}) and (#{right_col_name} < #{self[right_col_name]})" ) + self.class.base_class.find(:all, :conditions => "#{scope_condition} AND (#{left_col_name} > #{self[left_col_name]}) and (#{right_col_name} < #{self[right_col_name]})" ) end # Returns a set of only this entry's immediate children def direct_children - self.class.find(:all, :conditions => "#{scope_condition} and #{parent_column} = #{self.id}") + self.class.base_class.find(:all, :conditions => "#{scope_condition} and #{parent_column} = #{self.id}") end # Prunes a branch off of the tree, shifting all of the elements on the right @@ -199,10 +199,10 @@ module ActiveRecord return if self[right_col_name].nil? || self[left_col_name].nil? dif = self[right_col_name] - self[left_col_name] + 1 - self.class.transaction { - self.class.delete_all( "#{scope_condition} and #{left_col_name} > #{self[left_col_name]} and #{right_col_name} < #{self[right_col_name]}" ) - self.class.update_all( "#{left_col_name} = (#{left_col_name} - #{dif})", "#{scope_condition} AND #{left_col_name} >= #{self[right_col_name]}" ) - self.class.update_all( "#{right_col_name} = (#{right_col_name} - #{dif} )", "#{scope_condition} AND #{right_col_name} >= #{self[right_col_name]}" ) + self.class.base_class.transaction { + self.class.base_class.delete_all( "#{scope_condition} and #{left_col_name} > #{self[left_col_name]} and #{right_col_name} < #{self[right_col_name]}" ) + self.class.base_class.update_all( "#{left_col_name} = (#{left_col_name} - #{dif})", "#{scope_condition} AND #{left_col_name} >= #{self[right_col_name]}" ) + self.class.base_class.update_all( "#{right_col_name} = (#{right_col_name} - #{dif} )", "#{scope_condition} AND #{right_col_name} >= #{self[right_col_name]}" ) } end end |