Skip to content

Commit 9d3ff34

Browse files
authored
Add an option to allow users to detect "soft deletes" (#70)
1 parent f1ceea7 commit 9d3ff34

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ or use the purge option:
6464
$table->delete($entity, ['purge' => true]);
6565
```
6666

67+
## Detecting trashing
68+
If you need to distinguish between deletion and trashing the behavior
69+
adds the ['trash' => true ] option to the afterDelete event
70+
it creates when trashing.
71+
6772
### Cascading deletion
6873

6974
If you'd like to have related records marked as trashed when deleting a parent

src/Model/Behavior/TrashBehavior.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
class TrashBehavior extends Behavior
2929
{
30+
public const DELETE_OPTION_NAME = 'trash';
31+
3032
/**
3133
* Default configuration.
3234
*
@@ -118,6 +120,8 @@ public function beforeDelete(EventInterface $event, EntityInterface $entity, Arr
118120
return;
119121
}
120122

123+
$options[self::DELETE_OPTION_NAME] = true;
124+
121125
/** @var \Cake\ORM\Table $table */
122126
$table = $event->getSubject();
123127
$table->dispatchEvent('Model.afterDelete', [

0 commit comments

Comments
 (0)