odoo模型中many2one的 ondelete处理set null, restrict, cascade

odoo模型中many2one的 ondelete处理set null, restrict, cascade

 

odoo ORM中的many2one类型字段有 ondelete设置,对应数据表中关系处理

ondelete 设置当引用的record被删除是,如果对本record进行的行为,可填:set nullrestrictcascade

a = fields.Many2one('b', string='b', ondelete='set null')

则当对模型b进行delete操作时,会引发如下操作

set null: 当b中删除记录时,modelA中相关记录的a=null

cascade: 当b中删除记录时,modelA中相关记录也全部删除

restrict: 当b中删除记录时,如果modelA中存在对应记录,则无法操作 b 的删除

默认是: set null

原文地址:https://www.cnblogs.com/pywjh/p/13364493.html