邻接列表模型按路径选择
我正在尝试在我的层次结构系统中选择一个节点。
我有“/Path/To/Some/Node”(正是这种形式),我试图弄清楚如何获得“Node”的子节点。当然,“Node”是伪唯一的,因为它是 Some 内唯一名为“Node”的子节点,但“Path”内可能还有另一个“Node”,所以你显然不能只是爆炸,然后做一个简单的操作节点。
所以我需要创建一个选择查询来查看每个级别...
我显然可以通过使用大量查询来做到这一点,即。
Select id from Table where name = "Path"
Select id from Table where name = "To" and parent = "$id"
Select id from Table where name = "Some" and parent = "$id"
Select id from Table where name = "Node" and parent = "$id"
这并不理想... 有人可以建议吗?
I'm trying to select a node in my heirarchical system.
I have the "/Path/To/Some/Node" (In exactly that form) and I am trying to figure out how I can get the children of "Node". Naturally "Node" is pseudo-unique, in that it is the only child called "Node" inside of Some, but there could be another "Node" inside of "Path" so you obviously can't just explode and then do a simple Node.
So I need to create a select query which looks down each level...
I could obviously do this by using tonnes of querys, ie.
Select id from Table where name = "Path"
Select id from Table where name = "To" and parent = "$id"
Select id from Table where name = "Some" and parent = "$id"
Select id from Table where name = "Node" and parent = "$id"
This isn't ideal...
Can anyone advise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本文可能会有所帮助:
您可以扩展它以添加“路径”列,就像您提到的那样选择原始节点。然后使用单个附加查询(如本文中所述),您可以获取路径中的其余节点。
This article might help:
You could extend it to add the "path" column like you mentioned to select original node. Then using a single additional query (as described in the article), you could grab the rest of the nodes in the path.