Hi,
This topic is not specific to MODx, but could interest those using MODx as a framework.
I have a catalog of hard drives using five tables with this hierarchy :
categories > series > subseries > models > items
I want to represent it as a tree and wonder about the best model to store the data in this case.
There should not be frequent moves in the nodes. However, the possibility doing it as well as thus of inserting/deleting nodes is important.
All records in the miscellaneous tables have "id" and "parent" attributes, in the spirit of the adjacency list model, like the way MODx documents are hierarchied.
In order to avoid redundancy of infomation at the item level, each table has custom attributes.
For instance, the 2.5 inch format of all Momentus drives is stored in the "series" table.
The last level "items" stores things that cannot be stored elsewhere like the serial number.
So, basically things can be thought as object oriented with a basic class "Node" being extended:
class Node {id, parent}
class Serie extends Node {format}
class Model extends Node {capacity, speed, cache}
class Item extends Node {serial}
A category can have another category as parent.
A subserie can have another subserie as parent.
There is no hierarchical level limit to the number of subseries.
The drive models can be attached to either series or to subseries.
The items are always attached to drive models.
I heard about the Nested Set Model and its benefits over the Adjacency List Model (
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/)
and also its drawbacks (
https://robsite.net/nested-sets-suck-on-how-not-to-map-trees-into-a-relational-database/).
Concerning the Adjacency List Model, I appreciate the fact that it is simple to create SQL insert requests from a text file.
The software that I'm currently using stores both the "parent" of each node, as well as the full path from the root node in a chained listed of identifiers "eg. 20.36.81.83".
I assume this is for travelling the tree more efficiently. It seems using a B-Tree.
How to manage extended attributes (others than id, parent, name) ?
Should I store all the tree hierarchy in a table, have a column to store which kind a node belongs to and retrieve extended attributes using JOIN ?
Thank you for your ideas and advices.