Community mailing list archives

community@mail.odoo.com

Re: Unlink and ondelete="cascade"

by
Pedro M. Baeza
- 03/03/2016 05:28:27
Exactly, the ondelete is set at Postgres level, so you should take care of any custom unlink code in cascade models.

Regards.

2016-03-03 11:07 GMT+01:00 vak0160 <vak0160.work@gmail.com>:

Hello Community,

Please take a look at this snippet:

from openerp import models, fields, api

class ModelParent(models.Model):
    _name = "my_module.model_parent"

    name = fields.Char("Parent Name", required=True)

class ModelChild(models.Model):
    _name = "my_module.model_child"

    name = fields.Char("Child Name", required=True)

    parent_id = fields.Many2one("my_module.model_parent", required=True, ondelete="cascade")

    @api.multi
    def unlink(self):
        # do something here
        # This method only called when this record deleted directly, not if `ModelParent` is deleted

        return super(ModelChild, self).unlink()

The unlink method of ModelChild is not called when it’s parent (ModelParent) is deleted. Does ondelete="cascade" only delete the ModelChild records via database query and not from unlink method?

-- 
Regards,
Andre

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe