Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restrict, no action & set default in ondelete optional parameter for fields

Tags:

openerp

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

  • difference between RESTRICT and NO ACTION.
  • how SET DEFAULT is used in OpenERP 7?
    • where to set default value for the field ?
    • how to define set default value in python code itself?
like image 402
atchuthan Avatar asked Dec 12 '22 14:12

atchuthan


1 Answers

Take for example a Course with Students. On Students 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',
    ),
like image 80
taper Avatar answered Apr 10 '23 15:04

taper