2017 © Pedro Peláez
 

cakephp-plugin cake-soft-delete

Soft delete for CakePHP models.

image

burriko/cake-soft-delete

Soft delete for CakePHP models.

  • Wednesday, August 14, 2013
  • by burriko
  • Repository
  • 1 Watchers
  • 9 Stars
  • 2,556 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 1 Versions
  • 5 % Grown

The README.md

CakePHP Soft Delete Plugin

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)

Installation

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)

Configure

  1. Add the following line to your app/Config/bootstrap.php., (*4)

    CakePlugin::load('CakeSoftDelete');
  2. 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
  3. In the model that should be soft deletable add:, (*6)

    public $actsAs = array('CakeSoftDelete.SoftDeletable');
  4. 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)

Usage

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)

Limitations

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)

The Versions

14/08 2013

dev-master

9999999-dev https://github.com/burriko/cakephp-soft-delete

Soft delete for CakePHP models.

  Sources   Download

MIT

The Requires

 

cakephp behavior delete soft deletable