class ActiveRecord::Base

Public Class Methods

acts_as_tree(options = {}) click to toggle source
# File lib/xylem.rb, line 77
def self.acts_as_tree(options = {})
  config = {
    counter_cache: options[:counter_cache] || nil,
    dependent: options[:destroy] || :destroy,
    touch: options[:touch] || false
  }

  has_many :children,
    class_name: name,
    foreign_key: :parent_id,
    dependent: config[:dependent],
    inverse_of: :parent

  belongs_to :parent,
    class_name: name,
    counter_cache: config[:counter_cache],
    touch: config[:touch],
    inverse_of: :children

  extend  Xylem::ClassMethods
  include Xylem::InstanceMethods
end