Ticket #43: quicker_root.patch

File quicker_root.patch, 1.2 kB (added by rails, 10 months ago)
  • vendor/plugins/better_nested_set/lib/better_nested_set.rb

    old new  
    198198        # Returns this record's root ancestor. 
    199199        def root 
    200200          # the BETWEEN clause is needed to ensure we get the right virtual root, if using those 
    201           base_set_class.find(:first, :conditions => "#{scope_condition} \ 
    202             AND (#{parent_col_name} IS NULL OR #{parent_col_name} = 0) AND (#{self[left_col_name]} BETWEEN #{left_col_name} AND #{right_col_name})") 
     201          if( self[parent_col_name].blank? ) 
     202            self 
     203          else 
     204            base_set_class.find(:first, :conditions => "#{scope_condition} \ 
     205              AND (#{parent_col_name} IS NULL OR #{parent_col_name} = 0) AND (#{self[left_col_name]} BETWEEN #{left_col_name} AND #{right_col_name})") 
     206          end 
    203207        end 
    204208         
    205209        # Returns the root or virtual roots of this record's tree (a tree cannot have more than one real root). See the explanation of virtual roots in the README.