Deleting Entities
delete
You can delete an entity by calling the delete method on it.
var user = getInstance( "User" ).find( 1 );
user.delete();Soft Deletes
Soft deletes replace permanent deletion with a timestamp and automatically exclude deleted rows from normal queries. Enable them with softDeletes="true" and declare the timestamp attribute. The default attribute name is deletedDate.
component
extends="quick.models.BaseEntity"
accessors="true"
softDeletes="true"
{
property name="id";
property name="deletedDate" column="deleted_date";
}Use softDeleteColumn component metadata when your attribute has another name:
Calling delete() on a soft-deleting entity updates that timestamp and leaves the entity loaded.
Normal queries exclude trashed entities. Use withTrashed() to include them or onlyTrashed() to return only deleted rows.
Restore a loaded entity by clearing its deletion timestamp:
restore() uses the normal update lifecycle. Use forceDelete() when the row must be permanently removed.
deleteAll
Just like updateAll, you can delete many records from the database by specifying a query with constraints and then calling the deleteAll method.
ids
array
false
[]
An optional array of ids to add to the previously configured query. The ids will be added to a WHERE IN statement on the primary key columns.
Deletes matching entities according to the configured query.
Additionally, you can pass in an array of ids to deleteAll to delete only those ids. Note that any previously configured constraints will still apply.
For soft-deleting entities, deleteAll() timestamps matching rows instead of removing them. Bulk restore and permanent deletion are also available:
forceDeleteAll() also accepts an optional array of ids. Existing query constraints still apply.
Last updated
Was this helpful?