dev-master
9999999-dev https://github.com/burriko/cakephp-soft-deleteSoft delete for CakePHP models.
MIT
The Requires
- php >=5.3.0
- composer/installers *
by Graeme Tait
cakephp behavior delete soft deletable
Soft delete for CakePHP models.
Soft delete for CakePHP 2.x models. Transparently flags records as deleted instead of actually removing them. Will also then hide the deleted records from find operations., (*1)
If you're using composer then just add the following to your require block., (*2)
"burriko/cake-soft-delete": "2.0.*@dev"
If you're not, then clone/copy the contents of this directory to app/Plugins/CakeSoftDelete., (*3)
Add the following line to your app/Config/bootstrap.php., (*4)
CakePlugin::load('CakeSoftDelete');
Change your AppModel to extend SoftDeletableModel. You'll also need to add an appropriate App::uses to tell Cake where to load SoftDeletableModel. Basically Your AppModel class should start something like this., (*5)
<?php App::uses('SoftDeletableModel', 'CakeSoftDelete.Model'); class AppModel extends SoftDeletableModel
In the model that should be soft deletable add:, (*6)
public $actsAs = array('CakeSoftDelete.SoftDeletable');
Your model's database schema will need a field to act as a flag for whether a record has been deleted. By default this field is called 'deleted', but this can be changed in the behavior's settings. The field can be either a boolean or datetime (in which case it will be set to the time the field was deleted)., (*7)
Now when you delete records from this model they should just be soft deleted instead. Soft deleted records will not be present in results from find functions., (*8)
To include deleted records in results call the includeDeletedRecords() method on the model. You can then call excludeDeletedRecords() to hide them again., (*9)
Deletes will be cascaded to related models as usual, except for HABTM relations. This hasn't been a problem for me but is something to be aware of., (*10)
Soft delete for CakePHP models.
MIT
cakephp behavior delete soft deletable