콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
5 답글
19104 화면

I wanna create a Model "PU" to optionally record details (many) of each record (one) of Model "TIN". How do I use the ORM to trigger the deletion of the records on Model "PU" when the reference to it on Model "TIN" is deleted?


아바타
취소
베스트 답변

Hi,

Take the case of the sale order and sale order line, if you are looking to delete the order lines while deleting the sale order, you can use ondelete='cascade'

See, In the sale order line,

order_id = fields.Many2one('sale.order', string='Order Reference', required=True, ondelete='cascade', index=True, copy=False, readonly=True)


ON DELETE CASCADE referential action for a foreign key that allows you to delete data from child tables automatically when you delete the data from the parent table.


Thanks

아바타
취소
베스트 답변

Hello Andres Fontenele,

For your case need to connect with database from "UI" or "Terminal" then execute delete query of child relation table

Hope this help you

Best Thanks,

Ankit H Gandhi.

 

아바타
취소
작성자 베스트 답변

Thank you for your answer, Niyas.

I know about ondelete='cascade'. Sorry if I wasn't clear enough on my question. What I really want to know is how to delete the records when relation is lost. In your example it would be deleting the order.lines when these records aren't related to any sale.order.

Thanks.

아바타
취소

I think i haven't given the solution for what you have asked, with the reference lost means..., can you explain with a small example, so that it will be easy for me to understand

작성자

Pretty straight forward:

Parent Model A has these fields:

ID, DESC, QUANTITY, QUANTITY_DETAILS(ONE2MANY)

Child Model B has these fields:

ID, MODEL_A_ID (MANY2ONE), DETAIL1, DETAIL2

By setting the ondelete="cascade" on MODEL_A_ID field, the record on MODEL B will be deleted if the related MODEL A record is deleted, and that is clear.

The question is, assuming that there isn't a constraint preventing me to delete the content of the MODEL_A_ID field, if I set it to NULL it means that it has lost its relation to the parent MODEL A.

So the question is how to automatically delete this record on MODEL B, if it loses the relation in the way I have described above.

관련 게시물 답글 화면 활동
1
1월 25
1876
2
9월 22
9616
2
4월 22
4668
0
7월 21
7299
1
3월 21
5044