I am learning about optional parameter regarding fields for ondelete parameter. These are the predefined values: "cascade", "set null", "restrict", "no action", "set default"
Can anyone explain in detail about the
Take for example a Course
with Student
s. On Student
s is a foreign key to Course
. The ondelete
determines what happens with the student_id
column (on Course
) when the Student
is deleted.
CASCADE: Delete the Course
record with matching student_id
when Student
is deleted
RESTRICT: Cannot delete the Student
as long as it is related to a Course
.
NO ACTION: similar, but is a deferred check: You can delete the Student
but you have to make sure that the integrity is OK when the transaction is committed.
SET DEFAULT: uses openerp default definition (see _defaults
dict in the python model definition)
SET NULL: when a Student
gets deleted, the student_id
becomes NULL
in the DB.
In Python you can find these in _columns
defintion:
_columns = {
'student_id': fields.many2one(
'my.student',
'Student',
ondelete='set null',
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With