Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ or use the purge option:
$table->delete($entity, ['purge' => true]);
```

## Detecting trashing
If you need to distinguish between deletion and trashing the behavior
adds the ['trash' => true ] option to the afterDelete event
it creates when trashing.

### Cascading deletion

If you'd like to have related records marked as trashed when deleting a parent
Expand Down
4 changes: 4 additions & 0 deletions src/Model/Behavior/TrashBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*/
class TrashBehavior extends Behavior
{
public const DELETE_OPTION_NAME = 'trash';

/**
* Default configuration.
*
Expand Down Expand Up @@ -118,6 +120,8 @@ public function beforeDelete(EventInterface $event, EntityInterface $entity, Arr
return;
}

$options[self::DELETE_OPTION_NAME] = true;

/** @var \Cake\ORM\Table $table */
$table = $event->getSubject();
$table->dispatchEvent('Model.afterDelete', [
Expand Down