Mercurial > hg > soundsoftware-site
annotate lib/plugins/acts_as_tree/README @ 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 | 433d4f72a19b |
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 |