Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8e2f416ae4
Fetching contributors…

Cannot retrieve contributors at this time

file 44 lines (33 sloc) 1.539 kb
* This is very experimental code, and has not been    *
* tested on a wide range of databases.                *
*                                                     *
* Please exercise caution!                            *
*                                                     *
* Patches and suggestions for improvement may be      *
* submitted to the mailing list on rubyforge.         *


Allows you to create a model which forms a “materialized tree”, that is, one where each node contains an explicit path. This allows for efficient subtree searches [expensive in acts_as_tree] and insertion and removal of children

expensive in acts_as_nested_set

Requires ActiveRecord 2.1.x or later.


In your model:

class Foo < ActiveRecord::Base

a = Foo.find(1)
p a.children.count                     # count done via SQL
p a.descendants.find(:name=>'brian')   # search in subtree only

In your migration:

create_table :foos do |t|
  t.string   :path,       :null => false, :default => ""
  t.integer  :next_child, :null => false, :default => 0
add_index :foos, :path, :unique => true

See ActiveRecord::Acts::MaterializedTree::ClassMethods and ActiveRecord::Acts::MaterializedTree::InstanceMethods for more information.

Copyright (C) 2008 Brian Candler <>. Released under the MIT licence.

Something went wrong with that request. Please try again.