更新嵌套集中的祖先?
我使用嵌套集来表示 mysql 中的树,如下所示:
Tree
ID
title
lft
rgt
给定树中节点的 ID,更新该节点及其祖先的最简单/最佳方法是什么?
例如,假设节点 ID (36) 在树中的深度为 4 层。我想更新它的标题以及每个父节点的标题,一直到根,更新到单词“fish”。 (总共应该有四次更新。)
感谢您的帮助!
I am using nested sets to represent a tree in mysql, like so:
Tree
ID
title
lft
rgt
Given the ID of a node in the tree, what is the easiest / best way to UPDATE that node as well as all of it's ancestors?
For example, let's say that the node ID (36) is 4 levels deep in the tree. I would like to update its title, as well as every parent node's title, all the way to the root, to the word "fish". (Should be four updates in all.)
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了这个问题的答案,所以我将其发布在这里,以防其他人遇到类似的问题。
给定任意深度节点的 ID,这将更新该节点以及该节点的所有祖先。
I found an answer to this, so am posting it here in case anyone else encounters a similar problem.
Given the ID of an arbitrarily deep node, this will update the node and all ancestors of the node.