天天看点

Odoo中的层次数据组织

本人实在 http://blog.csdn.net/vnsoft/article/details/50000467 看到的该篇博客,但具体的出处没有找到。

网上有网友在问odoo数据库中,有许多的数据表都有parent_left和parent_right栏位,不清楚这个是作什么用的。其实这个是一种针对SQL数据库的设计方法,叫嵌套集合(Nested-sets)。网上有一些介绍,其中认为解释得比较好,通俗易懂的文章可以参考http://download.csdn.net/detail/vnsoft/9293921下载内容。

在odoo中,如果自己需要设计类似的架构,只要在osv.osv模型中增加几个参数即可:

_parent_name = "location_id"  
_parent_store = True  
_parent_order = 'name'  
           

其中_parent_name是指当前笔数据的父数据id栏位(默认值是parent_id),_parent_store表示使用parent_left,parent_right结构设计,如果使用此类设计,需要另外增加如下两个栏位定义:

'parent_left': fields.integer('Left Parent', select=),  
'parent_right': fields.integer('Right Parent', select=), 
           

如果你没有建,系统也会自动帮你创建。