[在阅读文档以及使用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
表示什么?
基本上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
运算符。**