Module: LoyalCore::ActsAsTree::ClassMethods

Defined in:
lib/loyal_core/acts/tree.rb

Instance Method Summary collapse

Instance Method Details

#loyal_core_acts_as_tree(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/loyal_core/acts/tree.rb', line 12

def loyal_core_acts_as_tree options={}
  attr_accessible :parent_id

  acts_as_nested_set  options.reverse_merge(
    :parent_column => 'parent_id',
    :left_column   => 'left_id',
    :right_column  => 'right_id',
    :depth_column  => 'depth',
    :dependent     => :destroy, # or :destroy
    :polymorphic   => false,
    :counter_cache => 'children_count'
  )

  scope :filter_by_root, -> do
    where :parent_id => nil
  end

  include InstanceMethods
  extend ExtendsMethods
end