Reputation: 16086
I have integrated Jstree in my application, now i want to understand different column in that table:
CREATE TABLE IF NOT EXISTS `tree` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` bigint(20) unsigned NOT NULL,
`position` bigint(20) unsigned NOT NULL,
`left` bigint(20) unsigned NOT NULL,
`right` bigint(20) unsigned NOT NULL,
`level` bigint(20) unsigned NOT NULL,
`title` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ;
This is the default table provided by the site.
Now if want to add a node, how do i know the value for left, right and level.
Upvotes: 1
Views: 687
Reputation: 12655
This looks like a mix of Adjacency list
an nested sets
.
Nested sets
are a better way of storing trees in a relational database.
It's hard to explain the principle you have to look here and here.
When you use nested sets
you don't need parent_id
.
I think jstree provided a sample table where you can choose by yourself what technique you use.
Another way of storing trees in a database would be a Closure Table. It's my personal favourite. It's simple but powerful. But you hardly find anything about it on the net.
Upvotes: 2