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
de8013e1
Commit
de8013e1
authored
May 30, 2015
by
cornernote
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move scopes to QueryBehavior
parent
da8679dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletion
+60
-1
SoftDeleteBehavior.php
behaviors/SoftDeleteBehavior.php
+15
-1
SoftDeleteQueryBehavior.php
behaviors/SoftDeleteQueryBehavior.php
+45
-0
No files found.
behaviors/SoftDeleteBehavior.php
View file @
de8013e1
...
@@ -25,7 +25,6 @@ use yii\db\Expression;
...
@@ -25,7 +25,6 @@ use yii\db\Expression;
* @property BaseActiveRecord $owner
* @property BaseActiveRecord $owner
*
*
* @author cornernote <cornernote@gmail.com>
* @author cornernote <cornernote@gmail.com>
* @author amnah <amnah.dev@gmail.com>
*/
*/
class
SoftDeleteBehavior
extends
Behavior
class
SoftDeleteBehavior
extends
Behavior
{
{
...
@@ -113,4 +112,18 @@ class SoftDeleteBehavior extends Behavior
...
@@ -113,4 +112,18 @@ class SoftDeleteBehavior extends Behavior
}
}
}
}
public
function
deleteds
()
{
$model
=
new
$this
->
owner
->
modelClass
();
$this
->
owner
->
andWhere
(
$this
->
attribute
.
' IS NULL'
);
return
$this
->
owner
;
}
public
function
undeleteds
()
{
$model
=
new
$this
->
owner
->
modelClass
();
$this
->
owner
->
andWhere
(
$this
->
attribute
.
' IS NOT NULL'
);
return
$this
->
owner
;
}
}
}
\ No newline at end of file
behaviors/SoftDeleteQueryBehavior.php
0 → 100644
View file @
de8013e1
<?php
namespace
cornernote\behaviors
;
use
yii\base\Behavior
;
use
yii\db\ActiveQuery
;
/**
* SoftDeleteQueryBehavior
*
* @usage:
* ```
* public function behaviors() {
* return [
* 'softDelete' => ['class' => 'cornernote\behaviors\SoftDeleteBehavior',
* 'attribute' => 'delete_time',
* 'value' => new Expression('NOW()'),
* ],
* ];
* }
* ```
*
* @property ActiveQuery $owner
*
* @author cornernote <cornernote@gmail.com>
*/
class
SoftDeleteQueryBehavior
extends
Behavior
{
/**
* @var string SoftDelete attribute
*/
public
$attribute
=
'deleted_at'
;
public
function
deleteds
()
{
return
$this
->
owner
->
andWhere
(
$this
->
attribute
.
' IS NULL'
);
}
public
function
undeleteds
()
{
return
$this
->
owner
->
andWhere
(
$this
->
attribute
.
' IS NOT 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