Ticket #36: fix_root_method.diff
| File fix_root_method.diff, 2.1 kB (added by rails, 1 year ago) |
|---|
-
lib/better_nested_set.rb
old new 208 208 end 209 209 end 210 210 211 # Returns root211 # Returns the root for the current set 212 212 def root 213 self.class.find(:first, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:parent_column]} IS NULL)")213 ancestors(:first) 214 214 end 215 215 216 # Returns roots when multiple roots (or virtual root, which is the same)217 def roots218 self.class.find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:parent_column]} IS NULL)", :order => "#{acts_as_nested_set_options[:left_column]}")219 end220 221 216 # Returns the parent 222 217 def parent 223 218 self.class.find(self[acts_as_nested_set_options[:parent_column]]) if self[acts_as_nested_set_options[:parent_column]] … … 225 220 226 221 # Returns an array of all parents 227 222 # Maybe 'full_outline' would be a better name, but we prefer to mimic the Tree class 228 def ancestors 229 self.class.find( :all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} < #{self[acts_as_nested_set_options[:left_column]]} and #{acts_as_nested_set_options[:right_column]} > #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column] )223 def ancestors(multiplicity = :all) 224 self.class.find(multiplicity, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} < #{self[acts_as_nested_set_options[:left_column]]} and #{acts_as_nested_set_options[:right_column]} > #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column] ) 230 225 end 231 226 232 227 # Returns the array of all parents and self
