Improving data structure
Currently in my application I have one table which is giving me a bit of trouble. The problem is, I have a value object that maps to this table. When the data is returned to me as an array of value objects, I must then loop through that array and start recursing, matching the ParentID to the parent ObjectID.
The ParentID column is either null (acting as a parent) or contains an ObjectID value.
I know there must be a better way to create this data structure so that I don't have to do recursive loops to match the ParentID with their ObjectID.
Any help with this is greatly appreciated.
Here is a table in description form:
+----------------+------------------+------+-----+---------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+------------------+------+-----+---------------------+-----------------------------+
| ObjectID | int(11) unsigned | NO | PRI | NULL | auto_increment |
| ObjectHeight | decimal(6,2) | NO | | NULL | |
| ObjectWidth | decimal(6,2) | NO | | NULL | |
| ObjectX | decimal(6,2) | NO | | NULL | |
| ObjectY | decimal(6,2) | NO | | NULL | |
| ObjectLabel | varchar(255) | NO | | NULL | |
| TemplateID | int(11) unsigned | NO | MUL | NULL | |
| ObjectTypeID | int(11) unsigned | NO | MUL | NULL | |
| ParentID | int(11) unsigned | YES | MUL | NULL | |
| CreationDate | datetime | YES | | 0000-00-00 00:00:00 | |
| LastModifyDate | timestamp | YES | | NULL | on update CURRENT_TIMESTAMP |
+----------------+------------------+------+-----+---------------------+-----------------------------+e
a source to share
You can use the nested set model. See a very good explanation here: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
a source to share