annotate .svn/pristine/d6/d6fb15df1769f8d322c674910838ec3cca56e211.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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