跳至内容
菜单
此问题已终结
1 回复
2654 查看

Hello, i have 2 classes:


class ModelA:

         _name = "model.a"


​first_field = fields.One2many(

​ ​comodel_name="model.b",

​ ​inverse_name="second_field",

​ ​ondelete="cascade"

​ ​)


class ModelB:

​_name = "model.b"


​second_field = fields.Many2one(

​ ​comodel_name="model.a",

​ ​ondelete="cascade"

​ ​)


If one2many is deleted, many2one will also be deleted. However, if many2one is deleted, the data in one2many still remains. How to delete the one2many if many2one has been deleted?



形象
丢弃
最佳答案

Hi,

This is not a usual behaviour, but you can achieve it by supering the unlink function.

def unlink(self) is the function that works when deleting a record, so you could call that function and super it and make necessary changes.

Regards

形象
丢弃
编写者

Thank you so much! It worked

相关帖文 回复 查看 活动
2
8月 15
4872
1
4月 23
5656
1
3月 23
2271
0
12月 22
2907
0
6月 21
2882