cornernote/yii2-softdelete Soft delete behavior for Yii2.

softdelete

Yii2 Soft Delete

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Soft delete behavior for Yii2.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require cornernote/yii2-softdelete "*"

or add

"cornernote/yii2-softdelete": "*"

to the require section of your composer.json file.

Usage

In your ActiveRecord class:

public function behaviors() {
    return [
        \cornernote\softdelete\SoftDeleteBehavior::className(),
        // or
        [
            'class' => \cornernote\softdelete\SoftDeleteBehavior::className(),
            'attribute' => 'deleted_time',
            'value' => new \yii\db\Expression('NOW()'), // for sqlite use - new \yii\db\Expression("date('now')")
        ],
    ];
}

then you can use explicitly $model->softDelete(), $model->hardDelete() and $model->unDelete() (for softly deleted models). Each of these methods return boolean result. Also $model->softDelete() calls indirectly from $model->delete(), which always returns false.

In your ActiveQuery class:

public function behaviors() {
    return [
        \cornernote\softdelete\SoftDeleteQueryBehavior::className(),
        // or
        [
            'class' => \cornernote\softdelete\SoftDeleteQueryBehavior::className(),
            'attribute' => 'deleted_time',
        ],
    ];
}

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



1.0.3 is the latest of 4 releases



BSD-3-Clause license
Stats
18 github stars & 5 github forks
0 downloads in the last day
38 downloads in the last 30 days
6436 total downloads