Garrett Johnson Wed Feb 23 19:55:31 -0500 2011

Subject: Recommendations for working with hierarchical data?

Does anyone have suggestions for working with hierarchical data like a tree of nested page records? I'm afraid the queries required to fully implement an adjacency list or nested set model are out of the scope of php.activerecord's finders, but I still want to get writable objects back from my model.


Yoan B Thu Feb 24 03:34:43 -0500 2011

This is what I did for a CMS last year, not using PHP AR though.

Implement a basic MPTT thing with nodes:

CREATE TABLE nodes (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
parent_id INT,
lft INT NOT NULL,
rght INT NOT NULL,
tree INT NOT NULL,
level INT NOT NULL DEFAULT 0
) ENGINE=InnoDB;

And then link your data to them. You will have a reusable tree storage thingy. MPTT is a bit complex but you can perform almost every kind of tree operation very easily after than, using UPDATE.

(1-1/1)