mptt

Building hierarchy objects from flat list of parent/child

I have a list of items in a hierarchy, and I'm attempting to parse this list out into an actual hierarchy of objects. I'm using modified pre-order tree traversal to store/iterate through this list, and so what I have is a subset of the tree, including all children, ordered by their "left" value. For example, given the tree: Item A It...

Problem using django mptt

Hi, I am having problem implementing django mptt. Here is my model: class Company(models.Model): name = models.CharField( max_length=100) parent = models.ForeignKey('self', null=True, blank=True, related_name='children') mptt.register(Company, order_insertion_by=['name']) And class Financials(models.Model): ...

Finding breadcrumbs for nested sets

I'm using nested sets (aka modified preorder tree traversal) to store a list of groups, and I'm trying to find a quick way to generate breadcrumbs (as a string, not a table) for ALL of the groups at once. My data is also stored using the adjacency list model (there are triggers to keep the two in sync). So for example: ID Name Par...

How to convert this MPTT array into a tree structure in PHP?

I've got hierarchal data in the database, stored in Modified Preorder Tree Traversal format. I'm pulling the data in a query that looks something like "SELECT ID, Left, Right, Name, etc FROM Table ORDER BY Left;". I'm trying to convert this data from a flat array the DB gives me into a tree-structure which I will then output as JSON wi...

Sort MPTT resultset into a multidimensional array PHP

I have been experimenting with the Modified Pre-Order Tree Traversal Pattern, my test case code is returning the results as expected however I am having trouble converting the 2D array into a multi-dimensional array to present it. Here is an example of a 3 level menu result, I need to convert this into a multi-dimensional array so that ...

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 ...

Suggested indices for a MPTT table

I'm just building a table to store hierarchical data using the Modified Pre-order Tree Traversal (MPTT) -- you know the one: each node stores the left and right IDs to find its descendants. I'm using a the CakePHP suggested model, which varies from the standard way by including the parent_id with each row. Here's the suggested table str...

Finding a subtree in a CakePHP Tree

In CakePHP, how do you select just a subtree in a model which actsAs tree? I tried this, to find the tree headed by the item with label = "My Label" $this->find("threaded", array( "conditions" => array( "label" => "My Label" ) )); ...however looking at the logs, it runs this SQL: SELECT Menu.id, Menu.parent_id, Menu....

MPTT ( Modified Preorder Tree Traversal) issue in PHP

Hi guys, My first post here! Seems like this is the place to get wise ;) I am currently in the middle of some testing with my first ever attempt to try the MPTT (Modified Preorder Tree Traversal) approach to storing data in my Mysql database with the help of PHP. However, I am trying to find out the most performance-oriented way to ge...

Django treebeard what are differences between AL, NS, MP

Hi! I'm trying to make a model for categorizing some objects. I already tried using django-mptt to easily retrieve related categories, and now I'm searching different solutions to find the best one. I can't find out though what are main differences between Materialized Path, Adjacency List and Nested Set. Wikipedia didn't give me a sh...

Modified preorder tree traversal - finding the next node

Hi, I have this data: id | parent_id | lft | rgt | name ===================================== 1 | 0 | 1 | 8 | abc 2 | 3 | 5 | 6 | jkl 3 | 1 | 2 | 3 | def 4 | 0 | 9 | 10 | mnno 5 | 1 | 4 | 7 | ghi I need to traverse this hierarchy in this order (ids): 1 > 3 > 5 > 2 > 4 H...

How to properly sort MPTT hierarchy data into multidimensional array ?

Helo there, im trying to figure out how to write a function that returns a multidimensional array, based on the data below: I know how to write the function using the "category_parent" value, but im just trying to write a function that can create a multidimensional array by JUST using the left and right keys. Any help greatly appreciat...

Have multiple trees in one table using CakePHP Tree Behavior

I'm converting a flat list into a tree in my CakePHP app and found that there is an existing behavior that has this functionality. My table is not one giant tree, but consists of many user-generated trees: basically, each user can create their own folder structure. However it seems that the Tree Behavior would only keep track of lft/rght...

Django-mptt completely buggy or am I doing it wrong?

I'm attempting to use django-mptt with very little luck. This is with Python2.5, windows, sqlite3, Django 1.2pre , django-mptt latest from svn. The code: model: class Node(models.Model): name = models.CharField(max_length=20, blank=True) parent = models.ForeignKey('self', null=True, blank=True, related_name='children') ...

MPTT to select root element mysql

Hi, What mysql query should i use to select root elements? Let's say i have tree structure like this: http://www.ipix.lt/desc/18496369 And i want to select (Vaisiai, Daržovės) elements. ...

Storing hierarchical (parent/child) data in Python/Django: MPTT alternative?

I'm looking for a good way to store and use hierarchical (parent/child) data in Django. I've been using django-mptt, but it seems entirely incompatible with my brain - I end up with non-obvious bugs in non-obvious places, mostly when moving things around in the tree: I end up with inconsistent state, where a node and its parent will disa...

Deeply nested subqueries for traversing trees in MySQL

I have a table in my database where I store a tree structure using the hybrid Nested Set (MPTT) model (the one which has lft and rght values) and the Adjacency List model (storing parent_id on each node). my_table (id, parent_id, lft, rght, alias) This question doesn't relate to any of the MPTT aspects of the tree but I thought I'd le...

Converting adjacency list tables to MPTT in SQL Server 2008

Is there a helpful tool or script resource to aid conversion from old-school adjacency list tables to MPTT? I would have thought it was a problem faced by a few cleverer souls than I in the past, and thought I'd check here first in case they came up with a clever solution in their travels - before embarking on my own journey to do such ...

data structure for transversal tree in PHP?

I don't have a background in CS or data structures. I want to make a PHP class that stores a modified preorder transversal tree, for manipulation and syncing with a database. Basically I need to store data like: +-------------+----------------------+-----+-----+ | category_id | name | lft | rgt | +-------------+-------...

Update all parent id's in a SQL mptt table

Hi, consider a SQL table, which stores hierarchical data using MPTT (Modified Preorder Tree Traversal) method. CREATE TABLE node ( id SERIAL NOT NULL, -- primary key -- Nested mptt tree model. lft INT NOT NULL, rgt INT NOT NULL, -- Some legacy a...