DeletionAllow parent delete when having related records : This property indicates if the parent record can be deleted if it has related records over this relation - true: When an attempt is made to delete the parent record, this relation WILL NOT be checked for the existence of records over this relation and thus it will not block the delete of the parent record
- false: When an attempt is made to delete the parent record, a check WILL be made for the existence of records over this relation. When related records exist over this relation, the delete of the parent record will be blocked and a ServoyException.NO_PARENT_DELETE_WITH_RELATED_RECORDS exception will be thrown.
Note |
---|
title | *Allow parent delete when having related records* overrules *Delete related records* |
---|
| The option Allow parent delete when having related records overrules the option Delete related records . This means that if the first option is set to false, the latter option is ignored. Setting the first option to false and the latter option to true will still block the delete. |
Note |
---|
title | All relations for the datasource checked on delete |
---|
| When an attempt is made to delete a record, each relation that uses the datasource of the record (that is to be deleted) as the source datasource is checked to see if it allows the delete to proceed. If one relation is found that blocks the delete, the entire delete will fail. |
Note |
---|
| If the option Allow parent delete when having related records is set to false on a relation, when a record is deleted from the datasource that is used as the source datasource for the relation, a check will be made to see if there are related records. If many relations exist with the option set to false, this can impact the performance of deletes. |
Delete related records : This property indicates if child records should be automatically deleted when the parent record is deleted - true: when the parent record is deleted and there are records over this relation, those related records will also get deleted.
- false: related records will remain untouched.
Note |
---|
| Deletes cascade down when encountering relations on the related records that are to be deleted that also have the Delete related records property set to true. This means that when a record from the CUSTOMERS datasource is deleted and the relation customer_to_orders has the Delete related records set to true, the order records will also be deleted. If there is a relation order_to_orderitems that also has the Delete related records property set to true, the orderitem records will also get deleted. |
Note |
---|
title | Deleting of related records can block the overall delete |
---|
| When a relation has the Delete related records property set to true, an attempt is made to also delete all individual related records. On each individual related record the checks mentioned previous will also be performed. If any of the related records blocks the delete, the entire delete is blocked. |
Example 1: A simple scenario This example defines three relations in the typical customer > orders > orderitems setup: Relation 1: customer_to_orders, allowParentDeleteWhenHavingRelatedRecords=true, deleteRelatedRecords=true Relation 2: order_to_orderitems, allowParentDeleteWhenHavingRelatedRecords=true, deleteRelatedRecords=true Relation 3: orderitem_to_product, allowParentDeleteWhenHavingRelatedRecords=true, deleteRelatedRecords=true If an attempt is made to delete a customer record which has order and the orders have orderitems, when the relations are setup as described above the customer record will be deleted, all the orders related to the customer are deleted and all orderitems related to the orders of the customer will be deleted. As Relation 3 has the deleteRelatedRecords property set to false, no attempt will be made to delete the product record related to the orderitems that are to be deleted. Example 2: Implementing business logic enforcement in the data layer This example defines four relations starting with the in the typical customer > orders > orderitems setup, followed by the following business logic enforced by the datamodel: If an order resulted in an Invoice, the id of the invoice is stored on the order record in the invoice_id column. If an order has a related invoice then it cannot be deleted Relation 1: customer_to_orders, allowParentDeleteWhenHavingRelatedRecords=true, deleteRelatedRecords=true Relation 2: order_to_orderitems, allowParentDeleteWhenHavingRelatedRecords=true, deleteRelatedRecords=true Relation 3: orderitem_to_product, allowParentDeleteWhenHavingRelatedRecords=true, deleteRelatedRecords=true Relation 4: order_to_invoice, allowParentDeleteWhenHavingRelatedRecords=false This setup is mostly the same as example 1, except for the additional fourth relation. This relation from the orders table to the invoices defines that the order record cannot be deleted if it has a related invoice record. In this setup, when an attempt is made to delete a customer record the delete is blocked if the customer has a related order that has a related invoice record. |