Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ruby / Rails gem or plugin to add a hierarchy tree to MongoRecord (MongoDB) models.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 doc added gemspec April 18, 2009
Octocat-spinner-32 lib It seems that the 'def []' method is not necessary May 20, 2009
Octocat-spinner-32 pkg RDoc tweaks April 18, 2009
Octocat-spinner-32 test First commit April 17, 2009
Octocat-spinner-32 Manifest First commit April 17, 2009
Octocat-spinner-32 README.rdoc RDoc tweaks April 18, 2009
Octocat-spinner-32 Rakefile First commit April 17, 2009
Octocat-spinner-32 init.rb First commit April 17, 2009
Octocat-spinner-32 mongo_tree.gemspec added gemspec April 18, 2009
README.rdoc

MongoTree

This is a simple way to add parent / child relationships to a Rails model that uses MongoDB and the MongoRecord plugin (not the Mongo ActiveRecord plugin.)

Installation

Gem:

sudo gem install mongo_tree

Plugin:

script/plugin install git://github.com/mully/mongo_tree.git

Usage

To use mongo tree, simply add the word “mongo_tree” to your model.

class Taxon < MongoRecord::Base
  mongo_Tree
end

Add Child:

@root = Taxon.new({:name=>"ROOT", :content=>"ROOT content"})
@root.save
@child1 = Taxon.new({:name=>"Child", :content=>"Child content"})
@root << @child1
@grandchild = Taxon.new({:name=>"GrandChild", :content=>"Grand content"})
@child1 << @grandchild

Access Children:

@root.children #access all first level childrent
@root.descendants #access all descendants (children, grandchildren, etc)
@root.parent #parent object
@root.ancestors #all ancestors (parent, grandparents, etc)

Delete Children:

@root.remove!(@child1)  #remove child from root.  the child will be resaved in it's own root node.

References

http://mongodb.org
http://github.com/mongodb/mongo-activerecord-ruby/tree/master
http://www.koders.com/ruby/fid995C0ABC8DD9B624D7C4E4D9EE319F374E4CA7FA.aspx?s=cdef%3Atree#L11
http://wiki.apache.org/couchdb/How_to_store_hierarchical_data

Copyright © 2009 Squeejee, released under the MIT license

Something went wrong with that request. Please try again.