Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 1/22/15, 6:08 AM

Postgresql provides a more effective way called 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.

In openerp fields can add using ondelete='cascade'

http://www.postgresql.org/docs/8.2/static/ddl-constraints.html

The available options are documented here: http://www.postgresql.org/docs/8.2/static/sql-createtable.html.

Ivan
on 1/22/15, 6:18 AM
0
Bharat Devnani
On 1/22/15, 6:16 AM

Hello LIBU,

Basically ondelete=cascade is Database functionality, not particularly odoo's.

If you wanted the related child records should get deleted automatically, when the parent record is deleted.

Take an example of Sale Order, if you want the Sale Order Lines should get deleted, when Sale order gets deleted.

for code example refer this : https://www.odoo.com/forum/help-1/question/delete-one2may-records-when-parent-record-is-deleted-30898

Hope this helps.

Regards,

Bharat

 

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 1/22/15, 6:15 AM

This is equivalent postgresql constraint ON DELETE CASCADE  (similary RESTRICT). In postgresql documentation, see:

Restricting and cascading deletes are the two most common options. RESTRICT prevents deletion of a referenced row. NO ACTION means that if any referencing rows still exist when the constraint is checked, an error is raised; this is the default behavior if you do not specify anything. (The essential difference between these two choices is that NO ACTION allows the check to be deferred until later in the transaction, whereas RESTRICT does not.) CASCADE specifies that when a referenced row is deleted, row(s) referencing it should be automatically deleted as well. There are two other options: SET NULL and SET DEFAULT. These cause the referencing columns to be set to nulls or default values, respectively, when the referenced row is deleted. Note that these do not excuse you from observing any constraints. For example, if an action specifies SET DEFAULT but the default value would not satisfy the foreign key, the operation will fail.

Analogous to ON DELETE there is also ON UPDATE which is invoked when a referenced column is changed (updated). The possible actions are the same.

Here is a simple example

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/22/15, 5:53 AM
Seen: 1904 times
Last updated: 3/16/15, 8:10 AM