nested-sets

Getting a modified preorder tree traversal model (nested set) into a <ul>

Hello everyone, I am trying to get my data which is hierarchically set up with a tree traversal model into an < ul> in order to show on my site. Here is my code: function getCats($) { // retrieve all children of $parent $query = "SELECT max(rght) as max from t_categories"; $row = C_DB::fetchSingleRow($query); $max = $row["max...

How to render all records from a nested set into a real html tree

I'm using the awesome_nested_set plugin in my Rails project. I have two models that look like this (simplified): class Customer < ActiveRecord::Base has_many :categories end class Category < ActiveRecord::Base belongs_to :customer # Columns in the categories table: lft, rgt and parent_id acts_as_nested_set :scope => :customer_...

awesome_nested_set

I have a select input: f.select :category_id, nested_set_options(Category, @categories) {|i| "#{'-' * i.level} #{i.name}" } What is the most efficient way to show only the categories with level > 1 ? ...

Triggers: Adjacency List to a Nested Set

I have an adjacency list on a legacy system that I would like to query recursively (need to get subtotals, etc). Can I make a trigger in MySQL that either store in a separate table, or alternatively store in separate columns in the same table the "Nested Set Equivalent" of a given set? My set is like this: +-------------+-------------...

Does allowing a category to have multiple parents make sense? Are there alternatives?

Short question: How should product categories that appear under multiple categories be managed? Is it a bad practice to do so at all? Background info: We have a product database with categories likes this: Products -Arts and Crafts Supplies -Glue -Paper Clips -Construction Paper -Office Supplies -Glue -Paper ...

Sorting items in MPTT result set?

I'm using the MPTT (modified preorder tree traversal) model to store hierarchical data in my MySQL table. (MPTT model: another description is nested set model.). My question is this: has anyone figured out a clever way to sort the results of a query on the tree? I could just go 'ORDER BY label', but then the result set will be sorted by ...

Nested Sets: How to query number of relations in many-to-many relationship

With a data structure like this: Tags {id, lft, rgt, depth, parentid} ObjectTags {id, tag_id, object_id} Objects {id} (the entries in Tags are organized as nested sets) I need a result that contains the Tag.id and the number of relationships that this Tag holds, including the relations of it's children but without duplicates. Exampl...

Rails, Restful Routes, and Awesome Nested Set

I have a data structure that is basically a tree using :wesome nested set: class category acts_as_nested_set What I want to achieve are routes like /categories/1/children/ /categories/1/children/new I know I could fake it by making a separate controller, but it seems a bit non-DRY. Are there any better ways to do this? ...

Count number of nodes in a level in a nested set

I am using Ruby (Ruby on Rails) and have a nested set of about 2000 nodes. Each node can only have two children. What is the best way to determine how many nodes are in each level? Do I have to crawl the entire tree looking for sibling to do this? Thanks! ...

MySQL Nested Sets - How to find parent of node?

I have your run of the mill nested set hierarchy type setup with the following columns: table name: myset columns: id, name, lft, rgt Does anyone know a query to determine the parent of a node? I read a couple places that it's handy to also have a *parent_id* column in your table to keep track of this, but it seems redundant and ...

Symfony: Model Translation + Nested Set

Hi, I'm using Symfony 1.2 with Doctrine. I have a Place model with translations in two languages. This Place model has also a nested set behaviour. I'm having problems now creating a new place that belongs to another node. I've tried two options but both of them fail: 1 option $this->mergeForm(new PlaceTranslationForm($this->obje...

Propel NestedSet creating Balanced Tree

Hi folks, I'm trying to use Propel's NestedSet feature. However, I'm missing something about inserting such that the tree is balanced as it is created (i.e. fill it in horizontally). Say I have these elements: root r1c1 r1c2 r2c1 r2c2 I want to insert r2c3 as the 1st child of r1c2 (i.e. fill row 2 before starting on r...

Does Nested Sets model work with article with many categories (many-to-many)?

Hi guys, I've been using the adjacency model for hierarchical data for the longest time and was searching the internet for a more efficient way to traverse trees until I read about Nested Sets yesterday. I liked the idea but have a few doubts............. Now I just wanted to know if it is possible to use the Nested Sets model for many...

Mysql: Optimizing finding super node in nested set tree

I have hierarchical data in a nested set model (table:projects): My table (projects): id, lft, rgt 1, 1, 6 2, 2, 3 3, 4, 5 4, 7, 10 5, 8, 9 6, 11, 12 7, 13, 14 ... Pretty printed: 1 2 3 4 5 6 7 To find the nearest super node of node 3 (knowing its lft value), i can do explain SELECT projects.* FROM projects WHERE 4 BETW...

How to Query Nested Set model with multiple roots plus filtering

Hello All, How do you query a nested set model with multiple roots, such trees in the same table? Currently, I added an extra column called the "Root" indicating the ID of the root node for all sub-tree nodes, however, I can't figure out the sql to retrieve them in the proper order I'm referring to this article Normally, the query t...

Threaded comment system nested set - multiple roots?

Hi, I'm implementing a threaded comment system for topics ie there is a topic and then threaded comments on each topic. Nested set 'seems' like the popular way to go, but how should I implement the roots of each thread? For example: the comments could be one massive nested set. I may be wrong but it seems like it would be slower al...

MongoDB nested sets

What're the best practices to store nested sets (like trees of comments) in MongoDB? I mean, every comment can have a parent comment and children-comments (answers). Storing them like this: { title: "Hello", body: "Please comment me!", comments: [ { author: "Peter", text: "Hi there", ...

PHP libraries for handling nested sets in MySQL

I read this article. http://dev.mysql.com/tech-resources/articles/hierarchical-data.html At the end of this article, it writes about PHP libraries for handling nested sets in MySQL. Does anyone know which PHP libraries he is talking about? ...

What does node mean in MySQL?

Could anyone explain what node means in MySQL? This one is talking about nested set. I am reading a document from Codeigniter's wiki and I am not sure what I am supposed to add for $node. getSubTreeAsHTML (line 704) Renders the fields for each node starting at the given node * return: Sample HTML render of tree string getSubTre...

convert from a 2d array to nested_set in Ruby on rails

I have a tree structure in a .csv file (nodes are of type text), and after reading the csv i want to store the data in a ruby object. I went through a few tree plugins and i think nested_set would serve the purpose for me. However, i am facing problem with fixing a format of csv file, so that i can read it and convert into tree object. I...