Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
Y
yii2-softdelete
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
digisin
yii2-softdelete
Commits
a7fb187c
Commit
a7fb187c
authored
May 30, 2015
by
cornernote
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update ActiveQuery behavior and update examples
parent
2d48edf1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
29 deletions
+46
-29
README.md
README.md
+33
-23
SoftDeleteBehavior.php
behaviors/SoftDeleteBehavior.php
+1
-1
SoftDeleteQueryBehavior.php
behaviors/SoftDeleteQueryBehavior.php
+12
-5
No files found.
README.md
View file @
a7fb187c
Soft delete behavior for Yii2
=======================
# Yii2 Soft Delete
Installation
------------
## Installation
The preferred way to install this extension is through
[
composer
](
http://getcomposer.org/download/
)
.
Either run
```
php composer.phar require --prefer-dist
vyants
/yii2-softdelete "*"
php composer.phar require --prefer-dist
cornernote
/yii2-softdelete "*"
```
or add
```
"
vyants
/yii2-softdelete": "*"
"
cornernote
/yii2-softdelete": "*"
```
to the require section of your
`composer.json`
file.
Usage
-----
```
public function behaviors() {
return [
'softDelete' => ['class' => 'vyants\softdelete\SoftDelete',
'statusAttribute' => 'status',
'timeAttribute' => false,
'deletedValue' => -1,
'activeValue' => 1,
],
];
}
```
\ No newline at end of file
## Usage
In your ActiveRecord class:
```
php
public
function
behaviors
()
{
return
[
[
'class'
=>
'cornernote\behaviors\SoftDeleteBehavior'
,
'attribute'
=>
'deleted_time'
,
'value'
=>
new
Expression
(
'NOW()'
),
],
];
}
```
In your ActiveQuery class:
```
php
public
function
behaviors
()
{
return
[
[
'class'
=>
'cornernote\behaviors\SoftDeleteQueryBehavior'
,
'attribute'
=>
'deleted_time'
,
],
];
}
```
\ No newline at end of file
behaviors/SoftDeleteBehavior.php
View file @
a7fb187c
...
...
@@ -14,7 +14,7 @@ use yii\db\Expression;
* ```
* public function behaviors() {
* return [
*
'softDelete' =>
[
* [
* 'class' => 'cornernote\behaviors\SoftDeleteBehavior',
* 'attribute' => 'delete_time',
* 'value' => new Expression('NOW()'),
...
...
behaviors/SoftDeleteQueryBehavior.php
View file @
a7fb187c
...
...
@@ -12,7 +12,7 @@ use yii\db\ActiveQuery;
* ```
* public function behaviors() {
* return [
*
'softDelete' =>
[
* [
* 'class' => 'cornernote\behaviors\SoftDeleteQueryBehavior',
* 'attribute' => 'delete_time',
* ],
...
...
@@ -31,14 +31,20 @@ class SoftDeleteQueryBehavior extends Behavior
*/
public
$attribute
=
'deleted_at'
;
public
function
deleteds
()
/**
* @return static
*/
public
function
deleted
()
{
return
$this
->
owner
->
andWhere
(
$this
->
attribute
.
' IS NULL'
);
return
$this
->
owner
->
andWhere
(
$this
->
attribute
.
' IS N
OT N
ULL'
);
}
public
function
undeleteds
()
/**
* @return static
*/
public
function
notDeleted
()
{
return
$this
->
owner
->
andWhere
(
$this
->
attribute
.
' IS N
OT N
ULL'
);
return
$this
->
owner
->
andWhere
(
$this
->
attribute
.
' IS NULL'
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment