教义 1.2 NestedSet 属性和关系从祖先继承
我有一个 Doctrine 1.2 项目,我正在重构该项目,以便使用具有多个根的 Doctrine Beahaviour NestedSet 为表提供树结构。
我需要的是从祖先到后代的继承(不是面向对象的常识),其中后代从最近的祖先继承属性,而他们自己的属性丢失了。同样的事情也会发生在关系上。
让我用一个例子来解释:
Category:
actAs:
NestedSet:
hasManyRoots: true
rootColumnName: root_id
columns:
name: string(50)
another_property: string(50)
active: boolean
Tag:
columns:
value: string(50)
CategoryTag:
columns:
category_id: integer
tag_id: integer
我想要执行的是:
- 检索一个类别是否处于活动状态,这意味着验证是否所有 祖先处于活动状态
- 如果给定类别缺少 another_property,则 ,继承自 其中存在最近祖先的
- 给定类别的检索标签;如果标签丢失,请检索它们 来自最接近的祖先
为了最大限度地提高速度和灵活性,您建议的最佳方法是什么?
I have a Doctrine 1.2 project that I'm refactoring in order to have a tree structure for a table using doctrine beahaviour NestedSet with multiple roots.
What I need is an inheritance (Not in the OO common sense) from ancestors to descendants in which the descendants inherits properties from the closest ancestor where their own properties are missing. Same thing would happen with relations.
Let me explain with an example:
Category:
actAs:
NestedSet:
hasManyRoots: true
rootColumnName: root_id
columns:
name: string(50)
another_property: string(50)
active: boolean
Tag:
columns:
value: string(50)
CategoryTag:
columns:
category_id: integer
tag_id: integer
What I want to perform is:
- retrieve if a category is active, that means verifying if all the
ancestors are active - if another_property is missing for a given category, inherit it from
closest ancestor in which is present - retrieve tags for a given category; if tags are missing, retrieve them
from the closest ancestor
What would you suggest as best approach in order to maximize speed and flexibility?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,这太简单了。只需获取具有所需关系的树,如下所示:
然后,您可以像这样渲染它:
注意,如果父节点不存在,如何从父节点获取“属性”。解决此问题的另一种方法是使用 Doctrine_Core::HYDRATE_RECORD_HIERARCHY。这允许在循环时调用 $nodes 上的方法。例如,您可以创建 Model::getClosestProperty() 方法,以从最接近的父级获取属性。但是,这不如阵列水合有效。
Well, this is faily simple. Just get the tree with relations that you need like this:
Then, you can render it like this:
Notice, how you can get 'property' from parent node, if it absent. Another way to address this issue is to use Doctrine_Core::HYDRATE_RECORD_HIERARCHY. This allows use to call methods on $nodes when looping. You can create a Model::getClosestProperty() method, for example, to get the property from closest parent. But, this is not as efficient as array hydration.