Deleting

Deleting entities

The defined entity has already been created and saved. But what if we need to remove it? That's easy too:

$article Content_Article::load$some_id );
$article->delete();

This is the same principle as for storage. So even deleting takes care of the subentities of the main entity, or the subentities of the subentity.

It is possible to delete only subentity alone (e.g. a certain language version of an article, etc.).

Again, it's good to keep in mind events - for example, after deletion, you may need to remove (or move) files that had context with the entity, etc. Again, the encapsulation principle should be followed, and the delete() method should take care of everything needed.

Like saving, the delete process is an SQL transaction (if backend can do it), which includes deleting any subnets. The transaction is started automatically, terminated automatically, and a rollback on failure also occurs.

A delete failure throws an exception.

Deleting partial records from the database

In some situations, it may be necessary to simply delete data directly from the database. The static dataDelete method allows this. Using it is simple, just create a query:

SomeClass::dataDelete( [
    
'master_entity_id' => $this->id,
    
'AND',
    
'author_user_id' => $user_id
] );

Warning! This is really just a direct deletion of data from the database table. Thus, in this case the system does not deal with entity relations, events, or starting and ending transactions.

Previous chapter
Saving
Next chapter
Creation of queries