Skip to content

Commit dbd71bf

Browse files
committed
fix. first and countAllResult Recove tempUseSoftDeletes
1 parent 7eb0763 commit dbd71bf

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

system/Model.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ public function first()
486486
$eventData = $this->trigger('afterFind', ['data' => $row]);
487487

488488
$this->tempReturnType = $this->returnType;
489+
$this->tempUseSoftDeletes = $this->useSoftDeletes;
489490

490491
return $eventData['data'];
491492
}
@@ -1577,7 +1578,8 @@ public function countAllResults(bool $reset = true, bool $test = false)
15771578
{
15781579
$this->builder()->where($this->table . '.' . $this->deletedField, null);
15791580
}
1580-
1581+
$this->tempUseSoftDeletes = $this->useSoftDeletes;
1582+
15811583
return $this->builder()->countAllResults($reset, $test);
15821584
}
15831585

tests/system/Database/Live/ModelTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,4 +1823,24 @@ public function testUndefinedMethodInBuilder()
18231823
->getBindings();
18241824
}
18251825

1826+
public function testFirstRecoverTempUseSoftDeletes()
1827+
{
1828+
$model = new UserModel($this->db);
1829+
$model->delete(1);
1830+
$user = $model->withDeleted()->first();
1831+
$this->assertEquals(1, $user->id);
1832+
$user2 = $model->first();
1833+
$this->assertEquals(2, $user2->id);
1834+
1835+
}
1836+
1837+
public function testcountAllResultsRecoverTempUseSoftDeletes()
1838+
{
1839+
$model = new UserModel($this->db);
1840+
$model->delete(1);
1841+
$this->assertEquals(4, $model->withDeleted()->countAllResults());
1842+
$this->assertEquals(3, $model->countAllResults());
1843+
1844+
}
1845+
18261846
}

0 commit comments

Comments
 (0)