annotate vendor/plugins/acts_as_tree/README @ 8:0c83d98252d9 yuya

* Add custom repo prefix and proper auth realm, remove auth cache (seems like an unwise feature), pass DB handle around, various other bits of tidying
author Chris Cannam
date Thu, 12 Aug 2010 15:31:37 +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