Module: SimpleTree::ClassMethods

Defined in:
lib/simple_tree.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_simple_tree(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/simple_tree.rb', line 9

def acts_as_simple_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

  self.send(:include, SimpleTree::InstanceMethods)
end