تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2685 أدوات العرض

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
أغسطس 15
4904
1
أبريل 23
5713
1
مارس 23
2339
0
ديسمبر 22
2984
0
يونيو 21
2909