Questions tagged [nested-sets]

The nested set model is a particular technique for representing nested sets (also known as trees or hierarchies) in relational databases.

From Wikipedia:

The nested set model is a particular technique for representing nested sets (also known as trees or hierarchies) in relational databases.

In the nested set model, nodes are numbered according to a tree traversal which visits each node twice, assigning numbers in the order of visiting, and at both visits. This leaves two numbers for each node, which are stored as two attributes. Querying becomes inexpensive: hierarchy membership can be tested by comparing these numbers. Updating requires renumbering and is therefore expensive. Refinements that use rational numbers instead of integers can avoid renumbering, and so are faster to update, although much more complicated.

392 questions
0
votes
1 answer

Using nestedset for site navigation

I would like to use a nested set to manage the navigation of a website. Would it be better to have a single page model and just make the parent names define the sections of the site or would it be better to have a category model which can be nested…
Dan
  • 43
  • 3
0
votes
2 answers

Adding Children with awesome_nested_set in rails

How do I add children to a parent using the awesome_nested_set plugin? I have a model, Unit, which is a nested set. I'd like to add sub-units. Within the edit view, how I let the user add children (sub-units) to the parent (unit)?
0
votes
1 answer

kohana framework 3.1.2 how make menu by Nested Sets

I am using kohana framework 3.1.2 and i want make nested menu... I am using ORM_MPTT class for this everything i am doing correctly... in view i am getting array , and in this array all categoris and sub categoris are in one row... if i…
0
votes
1 answer

Nested Sets Categories with Laravel 4

I have a categories table CREATE TABLE categories ( name clean_name image description lft rgt ) I need to be able to query all products within a category, organized by sub-categories. In other words: Products -Electronics --Portable >>> Product…
dcolumbus
  • 9,596
  • 26
  • 100
  • 165
0
votes
2 answers

Yii Nested Set (Yiiext). Trying to move a root node

I am using the fantastic extension by Yiiext "nested-set-behavior": https://github.com/yiiext/nested-set-behavior I am interested to know if anyone can let me know how to move (up or down) a root node when I am running the nested set with multiple…
Dave
  • 21
  • 1
  • 5
0
votes
2 answers

Nested Sets in mySQL with a left join

Could anyone please explain to me, why this mysql query throws an "Unknown column 'n.Id' in 'on clause'" error? It really doesn't make any sense to me. SELECT n.Id, n.Name, COUNT(*)-1 AS level, seo.URLName FROM NestedSetsTable…
Fitzi
  • 1,641
  • 11
  • 17
0
votes
1 answer

Nested set - can't move node to last parent

I'm currently facing a problem, that I can't solve. I am using a nested set for all my categories, and when I need to move them, there is some kind of bug. My problem is, that if I want to move a node - e.g. ID=2 from "top-level" to underlay ID=1…
denlau
  • 916
  • 2
  • 9
  • 21
0
votes
1 answer

MySQL Nested Sets adding node above selected node

I have been trying to figure this out for a while, I have a MySQL query to add a node into the list, example: Heren -Pakken -Schoenen Dames I'd like to add 'Children' before male. In this case, someone would say: Add Children before Male. This is…
Maarten de Graaf
  • 516
  • 2
  • 5
  • 20
0
votes
1 answer

MySQL nested set - select node's first N children

Tree example: ROOT -c1 -g11 -c2 -c3 -g31 -g32 -c4 -c5 -g51 This tree is stored in a MySQL table built on a nested set model (lft, rgt). How can I select only the first three children (c1,c2,c3) along with all their descendants? After…
h_45h
  • 169
  • 4
0
votes
1 answer

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…
shin
  • 31,901
  • 69
  • 184
  • 271
0
votes
1 answer

Threaded comment system nested set - multiple roots?

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…
riley
  • 2,387
  • 1
  • 25
  • 31
0
votes
1 answer

Symfony2 Doctrine NestedTree different Entity Types

I'm currently searching for a solution for this Problem: I have a nested Tree, but the Leafs can be different types of Entities. For Example I have a Entity "Project", with children that can be of the type "Folder" or "Textfile", Folders having the…
AlexK
  • 471
  • 1
  • 5
  • 14
0
votes
1 answer

How to turn a mysql table with a simple parent child relationship to a nested set?

I have a large mysql table - basically a slightly altered LDAP dump. 120K employees. The table is needed for lots of things but I have one task that is pegging the server - recursive queries. Each employee has the empl. id and supervisor id on…
blankip
  • 340
  • 5
  • 18
0
votes
1 answer

nested set db2 retrieve single path

I'm used to using nested sets in mysql and to retrieve a single path I would normally use the following : SELECT node.treeID, node.name, node.lft, node.rgt, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth FROM…
Early73
  • 473
  • 3
  • 7
  • 23
0
votes
1 answer

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

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…
Roy
  • 269
  • 2
  • 6
  • 12