Nested Set Model
0
0
+Community Article
Objectscript class that implements basic functionality of the nested set model.
This implementation:
Restrictions:
Index TreeIndex On (Root, Lft, Rgt);
#docker-compose build ....
#docker-compose up -d ....
#docker-compose exec iris iris session iris
USER>zn "NS"
NS>
NS > set c = ##class(MyApp.Category).%New()
NS > set c.Title = "root"
NS > write c.%Save()
1
NS > set c1 = ##class(MyApp.Category).%New()
NS > set c1.Title = "node 1"
NS > set c1.Parent = c
NS > write c1.%Save()
1
NS > set c2 = ##class(MyApp.Category).%New()
NS > set c2.Title = "node 2"
NS > do c.AddLastChild(c2)
NS > set c3 = ##class(MyApp.Category).%New()
NS > set c3.Title = "node 1-1"
NS > do c1.AddLastChild(c3)
NS > do ##class(MyApp.Category).PrintTree(c.%Id())
21 root(left=1, right=8)
- 22 node 1(left=2, right=5)
-
- 24 node 1-1(left=3, right=4)
- 23 node 2(left=6, right=7)
NS > write c2.MoveUp()
1
NS > do ##class(MyApp.Category).PrintTree(c.%Id())
21 root(left=1, right=8)
- 23 node 2(left=2, right=3)
- 22 node 1(left=4, right=7)
-
- 24 node 1-1(left=5, right=6)
NS > do ##class(MyApp.Category).%DeleteId(23)
NS > do ##class(MyApp.Category).PrintTree(c.%Id())
21 root(left=1, right=6)
- 22 node 1(left=2, right=5)
24 node 1-1(left=3, right=4)
+Community Article
Initial Release