Method deprecated or moved
This method is deprecated or moved on the latest stable version.
The last existing version (v1.2.6) is shown here.
acts_as_tree(options = {})
public
Configuration options are:
- foreign_key - specifies the column name to use for tracking of the
tree (default: parent_id)
- order - makes it possible to sort the children according to this
SQL snippet.
- counter_cache - keeps a count in a children_count column if set to
true (default: false).
# File activerecord/lib/active_record/acts/tree.rb, line 42
def acts_as_tree(options = {})
configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil }
configuration.update(options) if options.is_a?(Hash)
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 => :destroy
class_eval "include ActiveRecord::Acts::Tree::InstanceMethods\n\ndef self.roots\nfind(:all, :conditions => \"\#{configuration[:foreign_key]} IS NULL\", :order => \#{configuration[:order].nil? ? \"nil\" : %Q{\"\#{configuration[:order]}\"}})\nend\n\ndef self.root\nfind(:first, :conditions => \"\#{configuration[:foreign_key]} IS NULL\", :order => \#{configuration[:order].nil? ? \"nil\" : %Q{\"\#{configuration[:order]}\"}})\nend\n"
end