cornernote / yii2-softdelete
Soft delete behavior for Yii2.
Installs: 13 075
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 2
Forks: 5
Open Issues: 1
Type:yii2-behavior
Requires
- yiisoft/yii2: *
Requires (Dev)
- phpunit/dbunit: ~1.0
- phpunit/phpunit: ~4.0
- scrutinizer/ocular: ~1.1
This package is auto-updated.
Last update: 2024-11-19 18:47:57 UTC
README
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', ], ]; }