سؤال

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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

Also worth noting: there is a SoftDelete behavior bundled in CakeDC's Utils plugin.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top