# Delete Rules

reviewed: 2 March 2025

The Delete Rule Setting

The deleteRule tag of the <@BO> qualifier can have one of the following values:

Value Usage
deleteRule.Allowed Deleting instances of this entity from the datasource is allowed
deleteRule.NotAllowed Deleting instances of this entity from the datasource is never allowed
deleteRule.PerRelation Deleting instances of this entity from the datasource is allowed but special rules for related entities are in place

The following snippet of an entity shows the deleteRule tag in action:

resource main
    <@bo
        label: <@mlText 'Event'>
        table: 'eventEvent'
        primaryKey: 'id'
        deleteRule: deleteRule.PerRelation
        auditable: auditing.Auditable
        sequence: 'eventEvent'

Even when the delete rule allows deletion, exceptions may still apply:

  • The security tag may have a setting for canDelete that can still prohibit deletion (see here)
  • Code in the _eventAction method may prohibit deletion (see here)

Delete Relations

Note: delete relations are related to foreign keys which is explained in more detail here.

If the deleteRule tag is set to deleteRule.PerRelation, you should include the deleteRelations tag:

    // More stuff here
    deleteRelations: <
        <@bo/deleteRelation
            entity: 'event/visit'
            rule: deleteRelationRule.cascade
        >
    >
    // More stuff here

There can be multiple delete rules where each delete rule must refer to an entity that has a foreign key to this entity.

Compare the delete rules to the cascade delete rules supported by many relational databases.

Each delete rule has a number of tags:

Tag Usage
entity Name of entity that has a foreign key to this entity (i.e. me)
attribute Optional name of foreign key attribute (useful when entity has multiple foreign keys linking to me )
where Optional where clause to restrict rows of related entity
rule Specifies the delete rule
action Specifies the action in case of rule cascade

The rule can be one of two values:

Rule Usage
deleteRelationRule.cascade (Default rule); when a row is deleted, delete the associated rows in the linked entity
deleteRelationRule.noAssociates When there are associated rows in the linked entity, the delete is not allowed

The action can be one of two values (and is only relevant when the rule is deleteRelationRule.cascade):

Action Usage
deleteRelationAction.delete (Default action); associated rows in the linked entity are deleted
deleteRelationAction.unlink Associated rows in the linked entity are unlinked by setting the foreign key to null()

Note that the action deleteRelationAction.unlink does require the foreign attribute in the related entity to be optional so it can be set to null().

<End of document>