-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2053 from codeigniter4/deletedat
Change Model's deleted flag to a deleted_at datetime/timestamp. Fixes #2041
- Loading branch information
Showing
9 changed files
with
48 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,7 +143,7 @@ public function testFindRespectsSoftDeletes() | |
{ | ||
$this->db->table('user') | ||
->where('id', 4) | ||
->update(['deleted' => 1]); | ||
->update(['deleted_at' => date('Y-m-d H:i:s')]); | ||
|
||
$model = new UserModel($this->db); | ||
|
||
|
@@ -219,7 +219,7 @@ public function testFindAllRespectsSoftDeletes() | |
{ | ||
$this->db->table('user') | ||
->where('id', 4) | ||
->update(['deleted' => 1]); | ||
->update(['deleted_at' => date('Y-m-d H:i:s')]); | ||
|
||
$model = new UserModel($this->db); | ||
|
||
|
@@ -254,7 +254,7 @@ public function testFirstRespectsSoftDeletes() | |
{ | ||
$this->db->table('user') | ||
->where('id', 1) | ||
->update(['deleted' => 1]); | ||
->update(['deleted_at' => date('Y-m-d H:i:s')]); | ||
|
||
$model = new UserModel(); | ||
|
||
|
@@ -403,11 +403,11 @@ public function testDeleteWithSoftDeletes() | |
{ | ||
$model = new UserModel(); | ||
|
||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); | ||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]); | ||
|
||
$model->delete(1); | ||
|
||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 1]); | ||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL' => null]); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
@@ -416,7 +416,7 @@ public function testDeleteWithSoftDeletesPurge() | |
{ | ||
$model = new UserModel(); | ||
|
||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); | ||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]); | ||
|
||
$model->delete(1, true); | ||
|
||
|
@@ -461,7 +461,7 @@ public function testPurgeDeleted() | |
|
||
$this->db->table('user') | ||
->where('id', 1) | ||
->update(['deleted' => 1]); | ||
->update(['deleted_at' => date('Y-m-d H:i:s')]); | ||
|
||
$model->purgeDeleted(); | ||
|
||
|
@@ -479,7 +479,7 @@ public function testOnlyDeleted() | |
|
||
$this->db->table('user') | ||
->where('id', 1) | ||
->update(['deleted' => 1]); | ||
->update(['deleted_at' => date('Y-m-d H:i:s')]); | ||
|
||
$users = $model->onlyDeleted() | ||
->findAll(); | ||
|
@@ -757,7 +757,6 @@ public function testPasswordsStoreCorrectly() | |
'name' => $pass, | ||
'email' => '[email protected]', | ||
'country' => 'US', | ||
'deleted' => 0, | ||
]; | ||
|
||
$model->insert($data); | ||
|
@@ -1403,7 +1402,7 @@ public function testDeleteWithSoftDelete() | |
|
||
$model->delete(1); | ||
|
||
$this->seeInDatabase('job', ['id' => 1, 'deleted' => 1]); | ||
$this->seeInDatabase('job', ['id' => 1, 'deleted_at IS NOT NULL' => null]); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
@@ -1414,7 +1413,7 @@ public function testPurgeDeletedWithSoftDeleteFalse() | |
|
||
$this->db->table('job') | ||
->where('id', 1) | ||
->update(['deleted' => 1]); | ||
->update(['deleted_at' => time()]); | ||
|
||
$model->purgeDeleted(); | ||
|
||
|
@@ -1629,7 +1628,7 @@ public function testSoftDeleteWithTableJoinsFindAll() | |
{ | ||
$model = new UserModel(); | ||
|
||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); | ||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at' => null]); | ||
|
||
$results = $model->join('job', 'job.id = user.id') | ||
->findAll(); | ||
|
@@ -1645,7 +1644,7 @@ public function testSoftDeleteWithTableJoinsFind() | |
{ | ||
$model = new UserModel(); | ||
|
||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); | ||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at' => null]); | ||
|
||
$results = $model->join('job', 'job.id = user.id') | ||
->find(1); | ||
|
@@ -1661,7 +1660,7 @@ public function testSoftDeleteWithTableJoinsFirst() | |
{ | ||
$model = new UserModel(); | ||
|
||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); | ||
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at' => null]); | ||
|
||
$results = $model->join('job', 'job.id = user.id') | ||
->first(1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters