Questions tagged [nested-set-model]

Nested Set is a method for saving hierarchical data in a relational database

Nested Set is a method used to save hierarchical data in a relational database like MySQL, Postgresql, Oracle, etc ... The term is coined by Joe Celko in his book "Trees and Hierarchies in SQL"

Nested set also goes by the term "Modified Preorder Tree Traversal".

http://en.wikipedia.org/wiki/Nested_set_model

52 questions
1
vote
1 answer

SQL Query and PHP manipulation with Nested Set Model

I was reading this article, http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/. I wanted to give a simple example and then ask you how do I get the desired result? So here is the…
Shaan
  • 863
  • 2
  • 12
  • 25
1
vote
0 answers

Nested Set Model vs Materialized Path in MySQL

Just getting started on my first big(ish) project using mysql with quite a limited amount of technical knowledge. I'm faced with what seems to be the very common question of how to represent my tree hierarchy. I've been through Google quite…
1
vote
1 answer

EF Code-First and nested sets

I would like to create a nested set model inside my database. However, I have a problem, 'cause I don't know how to start the implementation using Entity Framework Code-First. Lets say I have such class: public class Category { public long Id {…
1
vote
2 answers

Ordering siblings in nested set model

I'm facing a problem with the nested set model, with MySQL. I can insert, delete, move subtrees to another parent, everything works fine. But I can't figure out how to order siblings. For example, I have these siblings : A, B, C, D, E And I want…
PJP
  • 756
  • 3
  • 15
1
vote
1 answer

A way to draw tree hierarchy from the Adjacency Model + Nested Sets Model (MPTT)

I have a .NET Core 2.2 application with SQL Server DB and I'm storing the hierarchy of the users using the Adjacency Model + Nested Sets Model. I'm using EF Core. My domain looks like this: public class MatrixPosition { public Guid…
XardasLord
  • 1,764
  • 2
  • 20
  • 45
1
vote
1 answer

How create menu automaticaly by php

I see nested set model method for create hierarchy category in database with MYSQL in this page : mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ But i didn't understand how can i make nested list for site category menu with these…
farzad
  • 612
  • 8
  • 24
1
vote
1 answer

How can I get all the nodes from a level in a Nested set model?

Is there an low-cost way of querying a table with a nested set model in order to get a collection of nodes from a specific level? i.e. How can I get IEnumerable from my tree level n? i.e. How can I get IEnumerable from my tree level n-1? Thanks!
gapin
  • 11
  • 3
1
vote
0 answers

Can we convert a adjacency list model of a cyclic graph into nested set model in RDBMS?

If a cyclic graph is stored in adjacency list model, then we query using CTEs which is very slow. But if there is a way to convert adjacency list model of cyclic graph into nested set model, then I guess the queries might run a little faster. I know…
Sai Ram
  • 101
  • 1
  • 3
1
vote
0 answers

getNestedList() method seems return wrong order in etrepat/baum laravel Package

According to etrepat/baum Docs, getNestedList() must return a key-value pair array indicating a node's depth with a separator. This is my Table data and Structure : By this Code : $categories = Category::getNestedList('name',NULL,'-'); return…
Ahmad Badpey
  • 6,348
  • 16
  • 93
  • 159
1
vote
1 answer

MySQL Nested Set Model with Laravel Relationships

Good evening! I am working on a package that is supposed to allow Laravel to have relationships based on MySQL Nested Set Model (lft and rgt keys). Legend: X, Y, Z, A, B, C are integer numbers. Let's assume that we want to use this with eshop…
Jerguš Lejko
  • 610
  • 4
  • 25
1
vote
3 answers

SQL Nested set query with join and sub query using "in" slow

I have some trouble with a query on a nested set structure that is slow (~4 sec.) select node.ID, node.Lft, node.Rgt, node.Level, count(ag.ArticleID) as count from Webshop.Category node left join Webshop.Category parent on parent.Lft between…
1
vote
0 answers

Fetching products by category slug using the Doctrine "Tree" extension

I currently have Product and Category entities, with a many-to-one relationship through the product's category property. The category has a slug defined using the @Gedmo\Slug annotation, which is working perfectly. Unfortunately the Tree extension's…
Adam
  • 959
  • 1
  • 10
  • 22
1
vote
0 answers

removing row from a table cause delete in another one

I have 2 tables: the categories table and the products table. there aren't direct relationships with external keys so no dependencies in SQL. Products table contains a field called category_id just to do joins with categories table in my views. Here…
Marco C
  • 45
  • 1
  • 8
1
vote
0 answers

How to order a Doctrine Nested Set Tree when querying

I have a table that acts as a nested set. The problem is, that the table have fields 'short_name' and 'long_name' and in different places i have to order the results accordingly. I'm using Doctrine's "HYDRATE_RECORD_HIERARCHY" hydration mode when…
sanya
  • 860
  • 1
  • 8
  • 20
1
vote
1 answer

MySQL automatic generation of nested set model on large data list?

I have a mysql table with 100,000 locations which I would like to apply the nested set model to so that I can easily generate ordered lists. For obvious reasons, this is bit of a large task to do manually, so I was hoping that considering my data is…
James
  • 656
  • 2
  • 10
  • 24