KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Deletion control with relations in 4D
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: September 13, 2002

Compatibility: 6.7.x and 6.8.x


You can ask 4D to enforce a deletion control when using relations. For example, in the case of an N to One relation, you may have a One record to which several N records are related.

If you delete this [One] record, since deletion control is disabled by default, you would have to search all the N records and delete them first. This means some additional steps and more code for you to write.

Another way to do it automatically is to enable deletion control for that relation. This means that when the One record is deleted, 4D will automatically try to delete all records binded to this record through the relation. In our case, 4D will try to delete the N records whose key fields have the same value as the One record, without adding a new line of code.

How to enable Deletion control?
First of all, for that feature to be available in your database, you need to select it in the database properties:


  1. In the Database Properties, go to the page Data Control and Access
  2. Check the box Allow Deletion Control.


To set the deletion control options for a particular relation:

  1. In the structure editor, double-click on the relation and click the Control page in the Relation properties dialog. The Deletion control button radios are now enabled.
  2. Select one of the following values:

    - Leave related many intact: This is 4D's default behavior. You can delete the One record. All Many records will remain in the Many table.

    - Delete related many: If 4D detects related records, they will be automatically deleted. Of course the action could fail if someone else is already locking one of theses records.

    - Cannot Delete if Related Many: This is the safest way. Usually, you need to delete the [Many] records first, before deleting the [One] record. This is to be sure that you will not try to delete a One record if [Many] records are still binded to this record.
  3. Click Apply to validate the changes.