Module: CollectiveIdea::Acts::NestedSet

Defined in:
lib/awesome_nested_set/move.rb,
lib/awesome_nested_set/tree.rb,
lib/awesome_nested_set/model.rb,
lib/awesome_nested_set/helper.rb,
lib/awesome_nested_set/columns.rb,
lib/awesome_nested_set/iterator.rb,
lib/awesome_nested_set/model/movable.rb,
lib/awesome_nested_set/set_validator.rb,
lib/awesome_nested_set/model/prunable.rb,
lib/awesome_nested_set/model/relatable.rb,
lib/awesome_nested_set/model/rebuildable.rb,
lib/awesome_nested_set/model/validatable.rb,
lib/awesome_nested_set/awesome_nested_set.rb,
lib/awesome_nested_set/model/transactable.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Columns, Helper, Model Classes: Iterator, Move, SetValidator, Tree

Instance Method Summary collapse

Instance Method Details

#acts_as_nested_set(options = {}) ⇒ Object

Configuration options are:

  • :parent_column - specifies the column name to use for keeping the position integer (default: parent_id)

  • :primary_column - specifies the column name to use as the inverse of the parent column (default: id)

  • :left_column - column name for left boundary data, default “lft”

  • :right_column - column name for right boundary data, default “rgt”

  • :depth_column - column name for the depth data, default “depth”

  • :scope - restricts what is to be considered a list. Given a symbol, it’ll attach “_id” (if it hasn’t been already) and use that as the foreign key restriction. You can also pass an array to scope by multiple attributes. Example: acts_as_nested_set :scope => [:notable_id, :notable_type]

  • :dependent - behavior for cascading destroy. If set to :destroy, all the child objects are destroyed alongside this object by calling their destroy method. If set to :delete_all (default), all the child objects are deleted without calling their destroy method.

  • :counter_cache adds a counter cache for the number of children. defaults to false. Example: acts_as_nested_set :counter_cache => :children_count

  • :order_column on which column to do sorting, by default it is the left_column_name Example: acts_as_nested_set :order_column => :position

See CollectiveIdea::Acts::NestedSet::Model::ClassMethods for a list of class methods and CollectiveIdea::Acts::NestedSet::Model for a list of instance methods added to acts_as_nested_set models



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/awesome_nested_set/awesome_nested_set.rb', line 48

def acts_as_nested_set(options = {})
  acts_as_nested_set_parse_options! options

  include Model
  include Columns
  extend Columns

  acts_as_nested_set_relate_parent!
  acts_as_nested_set_relate_children!

  attr_accessor :skip_before_destroy

  acts_as_nested_set_prevent_assignment_to_reserved_columns!
  acts_as_nested_set_define_callbacks!
end