Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2366 Widoki

Hello, so i have a relationship between 2 models that like so


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"

​)


After i delete a row from model A, linked  data in model B will also be deleted. However, if i delete a row in model B, the data is still showing in model A.


It only works on the One2many class. Is that the right behavior?

Awatar
Odrzuć
Najlepsza odpowiedź

This is a right behavior, the ondelete parameter only used on Many2one and you set it to cascade so the Model A is the parent and has many Childs from Model B so if you deleted the parent all Childs will be deleted but deleting the child will not delete the parent.

Awatar
Odrzuć
Autor

Then how can i delete the parent when deleting the child?

You can't delete the parent if you deleted the child.

Powiązane posty Odpowiedzi Widoki Czynność
3
sie 24
1751
1
wrz 21
21240
3
cze 18
15163
1
mar 15
5413