关于 parent_left, parent_right
-
南京-ccdos(1431494) 22:04:54
parent_left 或者right?
我至今没搞懂
前些天 问了一下,没回应
上海-空无一人(2158691) 22:05:07
我也在看。。。
苏州-秋风流云(154363268) 22:05:13
<record model="ir.actions.act_window" id="action_ziyuan_allfdcrm">
<field name="name">所有客户资源</field>
<field name="res_model">ziyuan.fdcrm</field>
<field name="domain">[('state','!=','draft'),('x_fuzr.parent_id.user_id','=',uid)]</field>
</record>
南京-ccdos(1431494) 22:05:26
关键也没列子
深圳-老刘(15251908) 22:11:28
这个不算嵌套,只是 多了几个条件
上海-空无一人(2158691) 22:13:18
所以刚刚那个该怎么写呢 找出当前hr.employee所属department的直接上级department下面所有的hr.employee.
这个domain要怎么写。。。
南京-ccdos(1431494) 22:15:22
“department”,“ child of”,"userid .id.department.parent"
上海-空无一人(2158691) 22:17:21
谢谢 我试试看
广州-步科(17779104) 22:22:24
parent_left parent_right 是用来计算子节点,避免递归
如 product.category 的定义:
_columns = {
'name': fields.char('Name', size=64, required=True, translate=True, select=True),
'complete_name': fields.function(_name_get_fnc, type="char", string='Name'),
'parent_id': fields.many2one('product.category','Parent Category', select=True, ondelete='cascade'),
'child_id': fields.one2many('product.category', 'parent_id', string='Child Categories'),
'sequence': fields.integer('Sequence', select=True, help="Gives the sequence order when displaying a list of product categories."),
'type': fields.selection([('view','View'), ('normal','Normal')], 'Category Type', help="A category of the view type is a virtual category that can be used as the parent of another category to create a hierarchical structure."),
'parent_left': fields.integer('Left Parent', select=1),
'parent_right': fields.integer('Right Parent', select=1),
}
南京-ccdos(1431494) 22:23:39
谢谢步科
我不明白的是,parent_left parent_right 还是 domain 的一个 运算符,就搞不懂了
广州-步科(17779104) 22:23:45
假如没有parent_left 和parent_right ,读子节点必须通过 parent_id 递归计算
有parent_left parent_right之后,计算就非常简单
如有以下记录结构:
Customers (1, 10)
Consumers (2, 3)
Partners (4, 9)
Basic Partners (5, 6)
Gold Partners (7,
Suppliers (11, 12)
广州-步科(17779104) 22:24:58
加入要读 Customers 的子节点:
SELECT id FROM partner_category
WHERE parent_left > 1 AND parent_left < 10
这样就可以了
parent_left 和 parent_right 中在domain 使用也是同样道理
上海-空无一人(2158691) 22:25:28
1, 10 在这里是什么意思?
广州-步科(17779104) 22:25:47
Customers (1, 10) 第一个是left 第二个是 right
深圳-老刘(15251908) 22:26:06
看懂了,左右边界
南京-ccdos(1431494) 22:26:09
下级 节点的范围
上海-空无一人(2158691) 22:26:46
范围是事先定义好的?
还是动态变化的?
广州-步科(17779104) 22:26:54
其实 parent_left 和parent_right 避免递归的话,把计算压力提前了,在创建和删除记录会重新计算
南京-ccdos(1431494) 22:26:58
插入时 计算
广州-步科(17779104) 22:27:24
以空间换时间,很经典的思路
上海-空无一人(2158691) 22:28:28
那left和right的区别是什么?
有一个不就能搞定了么
广州-步科(17779104) 22:28:38
左右边界呀
上海-稀饭(591958938) 22:28:39
左右
广州-步科(17779104) 22:28:48
仔细观察:
如有以下记录结构:
Customers (1, 10)
Consumers (2, 3)
Partners (4, 9)
Basic Partners (5, 6)
Gold Partners (7,
Suppliers (11, 12)
上海-空无一人(2158691) 22:28:52
加入要读 Customers 的子节点:
SELECT id FROM partner_category
WHERE parent_left > 1 AND parent_left < 10
应该是 parent_left>1 parent_right<10?
广州-步科(17779104) 22:29:39
呵呵,我错了,你是对的
深圳-老刘(15251908) 22:29:39
都在 1到10范围
上海-空无一人(2158691) 22:30:07
这里的1~10都是值id 》
?
指的是id?
广州-步科(17779104) 22:30:25
对
这种用法有一定的局限性,比如经常有插入删除场景中就不适用,计算量也不小。
OE 用的也不多
上海-空无一人(2158691) 22:31:22
主数据上用用蛮好
以查询为主
'parent_left': fields.integer('Left Parent', select=1),
'parent_right': fields.integer('Right Parent', select=1), 这些都是系统自带的字段?
广州-步科(17779104) 22:32:22
account.account
product.cat
stock.location
等这些都是读的场景多
南京-ccdos(1431494) 22:33:08
* operator must be a string with a valid comparison operator from this list:=, !=, >, >=, <, <=, like, ilike, in, not in, child_of, parent_left, parent_right
The semantics of most of these operators are obvious.
@广州-步科 我想请教, parent_left, parent_right 在这里作为 operator 是怎么工作的 ?
上海-空无一人(2158691) 22:33:15
向 write_uid一样 可以直接用?
广州-步科(17779104) 22:41:18
domain 最终都是转成SQL 语句的,作为 operator 也是一样:
如 [(id, parent_left, 1)] == parent_left > 1
[(id, parent_right, 10)] == parent_right < 10
其实就是转为 parent_left > 1 AND parent_right < 10
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login