Mongomapper-tree is a project mainly written in Ruby, based on the MIT license.
= simplificator-mongomapper-tree
== What
Representing a tree structure in mongodb using mongomapper. Highly experimental...just plaing around with mongodb and mongmapper.
So is it smart to store a tree in a document base database in a relational fashion? Not sure. Sometimes embedded documents wont work (especialy when quering and you do not know at what depth to query).
Changing the parent of a node is not supported, when creating a child node you have to specify the parent.
== How class TreeNode include MongoMapper::Document include MongoMapper::Tree
key :name, String
key :path, String
key :depth, Integer
key :parent_id, Mongo::ObjectID
belongs_to :parent, :class_name => 'TreeNode'
many :children, :class_name => 'TreeNode', :foreign_key => :parent_id
end
node = TreeNode.create(:name => 'root') child = TreeNode.create(:name => 'child', :parent => node)
node.depth node.ancestors node.self_and_ancestors node.descendants node.self_and_descendants
node.root node.ancestor_of?(child) node.descendant_of?(child)
== Note on Patches/Pull Requests
== Copyright
Copyright (c) 2010 pascalbetz. See LICENSE for details.