Module | ActiveRecord::Acts::Tree::InstanceMethods |
In: |
vendor/rails/activerecord/lib/active_record/acts/tree.rb
|
Returns list of ancestors, starting from parent until root.
subchild1.ancestors # => [child1, root]
# File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 68 68: def ancestors 69: node, nodes = self, [] 70: nodes << node = node.parent until not node.has_parent? 71: nodes 72: end
# File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 74 74: def root 75: node = self 76: node = node.parent until not node.has_parent? 77: node 78: end
# File vendor/rails/activerecord/lib/active_record/acts/tree.rb, line 84 84: def self_and_siblings 85: has_parent? ? parent.children : self.class.roots 86: end