我正在学习有关ondelete参数字段的可选参数。这些是预定义的值:“cascade”、“set null”、“restrict”、“no action”、“set default”
谁能详细解释一下
- RESTRICT 和 NO ACTION 的区别。
- OpenERP 7中如何使用SET DEFAULT?
- 在哪里设置字段的默认值?
- 如何在 python 代码本身中定义设置默认值?
我正在学习有关ondelete参数字段的可选参数。这些是预定义的值:“cascade”、“set null”、“restrict”、“no action”、“set default”
谁能详细解释一下
以 aCourse和Students 为例。On Students 是 的外键Course。确定删除时列 (on )ondelete会发生什么。student_idCourseStudent
CASCADE:删除Course匹配student_id时Student删除的记录
RESTRICT: 不能删除Student,只要它与Course.
NO ACTION:类似,但是是延迟检查:您可以删除,Student但必须确保在提交事务时完整性正常。
SET DEFAULT:使用 openerp 默认定义(参见_defaultspython 模型定义中的 dict)
SET NULL:当 aStudent被删除student_id时,NULL在 DB 中。
在 Python 中,您可以在_columns定义中找到这些:
_columns = {
'student_id': fields.many2one(
'my.student',
'Student',
ondelete='set null',
),