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

Propel NestedSet creating Balanced Tree

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…
Mike Crowe
  • 2,203
  • 3
  • 22
  • 37
0
votes
1 answer

Eloquent (Laravel4) and Nested-sets (Cartalyst) - How to get all articles from all descendants?

I'm new to Laravel 4 and some concepts it uses so go easy on me.. I'm developing a web store and I have a problem getting all the articles from all descendants in my catalogue tree. My tree structure is stored in the catalogues table using…
ObSeSSeN
  • 130
  • 6
0
votes
1 answer

Symfony: Model Translation + Nested Set

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…
fesja
  • 3,313
  • 6
  • 30
  • 42
0
votes
1 answer

Creating Dynamic forms for awesome nested set association with in Ruby on Rails

Hi i am kind of rails newbie and i have two models Category and Product class Category < ActiveRecord::Base attr_accessible :name, :parent_id has_many :products acts_as_nested_set validates_presence_of :name end class Product <…
0
votes
1 answer

Nested set query using NHibernate's QueryOver API

I'm storing a hierarchy of categories using the nested sets model, that is, each category has a Left and a Right value and each category has a higher Left and a smaller Right than any parent. I'd like to query all categories that are sub-categories…
Andre Loker
  • 8,368
  • 1
  • 23
  • 36
0
votes
4 answers

How to add a parent where clause on a Nested set sql query for a menu structure

Im' working with a fully functional nesetd set system in PHP I'm using it to build a simple menu structure with max depth = 2 Now I've added in the table an additional field to control the visibility state of every single menu item, in other words…
Fed03
  • 575
  • 5
  • 16
0
votes
1 answer

propel nested set behavior

I woudl like to build an oriented Graph using propel. The behavior I am looking for is similar to the nested set but with multiple parents for one child. What exists: P: Parent Node C: Child Node (0,1)P <- (0,n)C What I need: (0,n)P <- (0,n)C I…
Alexandre Mélard
  • 12,229
  • 3
  • 36
  • 46
0
votes
1 answer

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…
Joe Arasin
  • 103
  • 1
  • 9
0
votes
1 answer

Select the Items in Nested set

I have the following nested set. The cat.table: cat.ID Name Lft Rgt 1 A 1 8 2 B 2 5 3 C 3 4 4 D 6 7 5 E 9 14 6 F 10 11 7 G 12 13 OUTPUT: In brackets the count of the items.…
Gery
  • 147
  • 2
  • 10
0
votes
1 answer

MySQL query to get full paths of nodes from nested set

I have nested set table (MySQL) with about 1.5 million records in it. The table structure is: id | name | root_id | lft | rgt | level I need to get strings, containing names of all parent records plus record name, let's call it 'full_name'. For…
Y. E.
  • 687
  • 1
  • 10
  • 29
0
votes
2 answers

Select count of rows with unique values

I have a table that holds all of the items we have sold. There may be more than one item in an Order. I want to find the most popular item-color combinations where an order contains ONLY 1 item. I'm wondering if it's possible to find this in one…
TimSum
  • 738
  • 2
  • 8
  • 21
0
votes
1 answer

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 ?
astropanic
  • 10,800
  • 19
  • 72
  • 132
0
votes
2 answers

How to query for all sub-categories containing a product (directly in sub-category, or anywhere down the category-tree, eg. in sub-sub category)?

Schema: Category [ id, parent, children, left, right, level, root, products ] Product [ id, category, marketSegments ] MarketSegment [ id ] Also each entity has fields like name, description, slug but those are not relevant to my issue. Example…
ioleo
  • 4,697
  • 6
  • 48
  • 60
0
votes
1 answer

What category / filter structure is this using? Nested Interval?

You can see on their category links that it's quite obvious that the only portion of their URL that matters is the small hash near the end of the URL itself. For instance, Water Heaters category found under Heating/Cooling…
0
votes
2 answers

Updating nested Array data using mongodb

I have nested data: Object _id: "90fac6ab-b88e-42a1-8e91-80ee25951ec7" answers: Array[4] 0: Object name: "myData" owned_by: "273b7291-df2b-494c-bd9b-64e71283447e" score: 0 I am trying to update, only a specific nested answer…
JZ.
  • 21,147
  • 32
  • 115
  • 192