openerp中的左父母和右父母 [英] Parent left and Parent Right in openerp
问题描述
左父母和右父母是什么?
What is Parent left and Parent right?
它在 Openerp 中如何工作?
谢谢
推荐答案
正如Raphael Collet在中所解释的那样OpenERP服务器:
As Raphael Collet explains in his answer about OpenERP Server:
parent_left和parent_right是与以下内容相关的特殊字段 parent_id字段.这些字段的目的是进行查询 在层次结构中有效执行:使用parent_left和 parent_right,您可以检索节点的所有后代,而无需 进行递归查询.
parent_left and parent_right are special fields that are related to the parent_id field. The purpose of those fields is to make queries within the hierarchy execute efficiently: with parent_left and parent_right, you can retrieve all the descendants of a node without making recursive queries.
考虑层次结构中的两个节点A和B. A和B可以成为伙伴 例如,类别.它们的整数字段parent_left和 parent_right是这样的:
Consider two nodes A and B in the hierarchy. A and B can be partner categories, for instance. Their integer fields parent_left and parent_right are such that:
B is a descendant of A in the hierarchy (defined by parent_id)
当且仅当
A.parent_left < B.parent_left and
A.parent_left < B.parent_right and
B.parent_left < A.parent_right and
B.parent_right < A.parent_right
因此,假设您有六个合作伙伴类别,如下所示.你可以 通过遍历树来分配parent_left和parent_right.结果 在每个节点旁边的括号中显示.注意那里的值 是最优的实际上,您可以在数字上留出空白.
So, imagine that you have six partner categories like below. You can assign parent_left and parent_right by traversing the tree. The result is show in parentheses next to each node. Note that the values there are optimal; in practice, you can leave gaps in the numbers.
- 客户(1,10)
- 消费者(2,3)
- 合作伙伴(4,9)
- 基本合作伙伴(5,6)
- 金牌合作伙伴(7,8)
- Customers (1, 10)
- Consumers (2, 3)
- Partners (4, 9)
- Basic Partners (5, 6)
- Gold Partners (7, 8)
您可以使用单个SQL检索客户"的所有子类别 询问.请注意,值1和10是parent_left和 客户的parent_right;可以将它们作为查询的一部分进行检索 本身.
You can retrieve all the subcategories of Customers with a single SQL query. Note that the values 1 and 10 are the parent_left and parent_right of Customers; they can be retrieved as part of the query itself.
SELECT id FROM partner_category WHERE parent_left > 1 AND parent_left < 10
最后一句话是可以更新parent_left和parent_right 而不遍历整个层次结构.删除节点不会 需要任何更改.要添加节点,您可以调整parent_left 和parent_right具有两个UPDATE查询:一个用于腾出一些空间" 在新节点祖先的parent_left和parent_right之间, 和一个移动新节点的parent_left和parent_right 跟随兄弟姐妹及其后代.所以parent_left和 parent_right可以得到有效维护.
The last remark is that parent_left and parent_right can be updated without traversing the whole hierarchy. Removing a node does not require any change. For adding a node, you can adapt the parent_left and parent_right with two UPDATE queries: one to "make some space" between the parent_left and parent_right of the new node's ancestors, and one to shift the parent_left and parent_right of the new node's following siblings and their descendants. So parent_left and parent_right can be maintained efficiently.
这篇关于openerp中的左父母和右父母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!