Module: DataMapper::Is::Tree
- Defined in:
- lib/dm-is-tree/is/tree.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
Instance Method Summary collapse
- #is_a_tree(options = {}) ⇒ Object
-
#is_tree(options = {}) ⇒ Object
(also: #can_has_tree)
Configuration options are:.
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/dm-is-tree/is/tree.rb', line 6 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#is_a_tree(options = {}) ⇒ Object
89 90 91 92 |
# File 'lib/dm-is-tree/is/tree.rb', line 89 def is_a_tree( = {}) warn('#is_a_tree is depreciated. use #is :tree instead.') is :tree, end |
#is_tree(options = {}) ⇒ Object Also known as: can_has_tree
Configuration options are:
-
child_key
- specifies the column name to use for tracking of the tree (default:parent_id
) -
constraint
- allows a constraint option to be set on the ‘has n` association. Only valid when dm-constraints is used.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dm-is-tree/is/tree.rb', line 64 def is_tree( = {}) if [:class_name] warn '+options[:class_name]+ is deprecated, use :model instead' [:model] = .delete(:class_name) end = { :model => name, :child_key => :parent_id }.merge() if Hash === @tree_options = include DataMapper::Is::Tree::InstanceMethods extend DataMapper::Is::Tree::ClassMethods = { :model => [:model], :child_key => Array([:child_key]) } = [:order] ? { :order => Array([:order]) }.merge() : .merge!(:constraint => [:constraint]) if [:constraint] belongs_to :parent, .merge(:required => false) has n, :children, class << self alias_method :root, :first_root # for people used to the ActiveRecord acts_as_tree end end |