Revision 1298:4f746d8966dd lib/plugins/acts_as_tree/lib/active_record

View differences:

lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb
46 46
          belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache]
47 47
          has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => configuration[:dependent]
48 48

  
49
          class_eval <<-EOV
50
            include ActiveRecord::Acts::Tree::InstanceMethods
49
          scope :roots, where("#{configuration[:foreign_key]} IS NULL").order(configuration[:order])
51 50

  
52
            def self.roots
53
              find(:all, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})
54
            end
55

  
56
            def self.root
57
              find(:first, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})
58
            end
59
          EOV
51
          send :include, ActiveRecord::Acts::Tree::InstanceMethods
60 52
        end
61 53
      end
62 54

  

Also available in: Unified diff