]> source.dussan.org Git - redmine.git/commitdiff
Replaces acts_as_tree #roots class method with a scope.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Dec 2012 20:41:03 +0000 (20:41 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Dec 2012 20:41:03 +0000 (20:41 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10919 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb

index a1c83cf50d72130a6c7ed71f2749551a0f0e57d6..4e5f37182e16dfec6167fdea6895eeb1793879d7 100644 (file)
@@ -46,17 +46,7 @@ module ActiveRecord
           belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache]
           has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => configuration[:dependent]
 
-          class_eval <<-EOV
-            include ActiveRecord::Acts::Tree::InstanceMethods
-
-            def self.roots
-              find(:all, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})
-            end
-
-            def self.root
-              find(:first, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})
-            end
-          EOV
+          scope :roots, where("#{configuration[:foreign_key]} IS NULL").order(configuration[:order])
         end
       end