[英]Why odoo One2many does not hard delete row?
I have observed the table where an One2many
field is related.我观察到与One2many
字段相关的表。 When I deleted a row of an One2many
field thorough One2many
widget the real row inside the table is not deleted.当我通过One2many
小部件删除One2many
字段的一行时,表内的真实行不会被删除。
The row just got the foreign key column set to NULL
.该行刚刚将外键列设置为NULL
。
Can we change this behavior to permanently (hard) delete the related row?我们可以将此行为更改为永久(硬)删除相关行吗?
Why did the designer choose this behavior in the first place?为什么设计师首先选择这种行为? Any technical consideration why?任何技术考虑为什么?
Thanks谢谢
In relation field, there is parameter Ondelete.在关系字段中,有参数 Ondelete。 It has 3 options它有 3 个选项
Can we change this behavior to permanently (hard) delete the related row?我们可以将此行为更改为永久(硬)删除相关行吗?
To achieve this you have to declare M2O with 2 parameters.为此,您必须使用 2 个参数声明 M2O。 It must be required and ondelete must be cascade.它必须是必需的,并且 ondelete 必须是级联的。 Example of Odoo Odoo 示例
class ProductAttribute(models.Model):
_name = "product.attribute"
value_ids = fields.One2many('product.attribute.value', 'attribute_id', 'Values', copy=True)
class ProductAttributeValue(models.Model):
_name = "product.attribute.value"
attribute_id = fields.Many2one('product.attribute', string='Attribute', ondelete='cascade', required=True, index=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.