Module: Sequel::Plugins::Tree
- Defined in:
- lib/sequel_tree.rb
Overview
The Tree plugin adds additional associations and methods that allow you to treat a Model as a tree.
A column for holding the parent key is required and is :parent_id by default.
This may be overridden by passing column name via :key
Optionally, a column to control order of nodes returned can be specified by passing column name via :order.
Examples:
class Node < Sequel::Model
plugin :tree
end
class OrderedNode < Sequel::Model(:nodes)
plugin :tree, :order => :position
end
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
Class Method Details
.configure(model, opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/sequel_tree.rb', line 23 def self.configure(model, opts = {}) model.instance_eval do @parent_column = opts[:key] || :parent_id @order_column = opts[:order] many_to_one :parent, :class => self, :key => @parent_column one_to_many :children, :class => self, :key => @parent_column, :order => @order_column end end |