Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 1.3 alternative to SoftDeletable Behavior?

Does anyone know of an alternative to the SoftDeletable Behavior that is compatible with Cake 1.3.x?

If there aren't any ready behaviors available, any suggestions on how I go about doing this in the latest Cake?


Figured out a quick hack. First and foremost, if your table introduce a tinyint(1) unsigned field named deleted which defaults to 0.

In app/app_model.php, add in the following function:

function softDelete( $id ) {
    if( $id && $this->hasField( 'deleted' ) ) {
        $this->id = $id;
        return $this->saveField( 'deleted', 1 );
    }

    return false;
}

and then from your controller's method (that performs the delete) call,

$this->Model->softDelete( $id );

Catch is, wherever you perform a find(), you need to specify the condition deleted != 1.

Still trying to figure out how to implement this in the same manner as the SoftDeletable behavior.

like image 428
miCRoSCoPiC_eaRthLinG Avatar asked Feb 25 '23 14:02

miCRoSCoPiC_eaRthLinG


1 Answers

i've adapted mariano's behavior to 1.3. look here - https://github.com/evilbloodydemon/cakephp-softdeletable2

like image 187
evilbloodydemon Avatar answered Mar 16 '23 19:03

evilbloodydemon