odoo过滤器域运算符“ child_of”的解释及其相对于“ in”运算符的优先级

问题描述 投票:1回答:1

[在阅读文档以及使用child_of运算符而不是使用child_of运算符进行过滤后,我不确定in的工作是什么

Odoo v10域文档可以在here中找到,其中指出child_of的以下内容

is a child (descendant) of a value record.
Takes the semantics of the model into account (i.e following the relationship field named by _parent_name)

考虑具有指向模型product.product的名为pos_categ_id的多字段的模型pos.category

为了只获得PoS类别ID为x的产品,可以使用['pos_categ_id', 'child_of', x]的域值,但是['pos_categ_id', 'in', [x]]似乎也做同样的事情。

[此外,in运算符可以用于与上面示例相同格式的many2many和one2many字段,而对这两种字段类型使用child_of运算符会导致错误。

[[0]为many2many字段的域['session_ids', 'child_of', [572]]的示例导致以下错误session_ids

所以,在什么情况下Invalid field 'parent_id' in leaf \"<osv.ExtendedLeaf: ('parent_id', 'in', [572]) on pos_session (ctx: )>\"优先于child_of运算符?两者似乎功能相同,只是in可以在所有类型的关系字段上使用。其次,文档in的第二行由短语child_of表示什么?

odoo odoo-10
1个回答
0
投票

基本上following the relationship field named by _parent_name功能由odoo提供,而不是python。

但是要理解它,您必须了解数据库概念中的child_of,'child`关系。

如果您的任何表都使用self join,如下例所示。

parent

_name = 'my.table'

在上述情况下,您的模型已经连接好了。在Odoo中,这种情况下,您可以在域中使用parent_id = fields.Many2one('my.table', string='Parent Id')运算符。

因此,它将像child_of这样在数据库中搜索。

对于parent_id = <your_value>域,

您可以在in字段中传递需要搜索的数据列表。它类似于任何数据库id运算符。**

© www.soinside.com 2019 - 2024. All rights reserved.