annotate vendor/plugins/acts_as_tree/README @ 669:202986dd17e4 live bibliography_plugin_alpha

Merge from branch "cannam_integration"
author Chris Cannam
date Fri, 09 Sep 2011 16:56:21 +0100
parents 513646585e45
children
rev   line source
Chris@0 1 acts_as_tree
Chris@0 2 ============
Chris@0 3
Chris@0 4 Specify this +acts_as+ extension if you want to model a tree structure by providing a parent association and a children
Chris@0 5 association. This requires that you have a foreign key column, which by default is called +parent_id+.
Chris@0 6
Chris@0 7 class Category < ActiveRecord::Base
Chris@0 8 acts_as_tree :order => "name"
Chris@0 9 end
Chris@0 10
Chris@0 11 Example:
Chris@0 12 root
Chris@0 13 \_ child1
Chris@0 14 \_ subchild1
Chris@0 15 \_ subchild2
Chris@0 16
Chris@0 17 root = Category.create("name" => "root")
Chris@0 18 child1 = root.children.create("name" => "child1")
Chris@0 19 subchild1 = child1.children.create("name" => "subchild1")
Chris@0 20
Chris@0 21 root.parent # => nil
Chris@0 22 child1.parent # => root
Chris@0 23 root.children # => [child1]
Chris@0 24 root.children.first.children.first # => subchild1
Chris@0 25
Chris@0 26 Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license