Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2810 มุมมอง

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
Show related objects of the same model. แก้ไขแล้ว
2
ส.ค. 15
4953
1
เม.ย. 23
5818
1
มี.ค. 23
2410
0
ธ.ค. 22
3043
0
มิ.ย. 21
2981