Skip to content

Commit df79ab3

Browse files
authored
Override the count method to apply deletionTimestamp to the query (#19)
* Overload the count method and apply the deletionTimestamp to the query * Add test for overloaded count method
1 parent 52187f1 commit df79ab3

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/Mapping.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ public function findAll()
8282
return $this->map(parent::findAll());
8383
}
8484

85+
/**
86+
* Counts all records.
87+
*
88+
* @return int
89+
*/
90+
public function count(string $column = '*')
91+
{
92+
if ($this->definition->getDeletionTimestamp()) {
93+
$this->isNull($this->prefixTableNameTo($this->definition->getDeletionTimestamp()));
94+
}
95+
96+
return parent::count($column);
97+
}
98+
8599
/**
86100
* Maps the provided array into the database.
87101
*

tests/MappingTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ public function testFindOne()
7272
$this->assertEquals(400, $customer['orders'][0]['items'][1]['amount']);
7373
}
7474

75+
public function testCount()
76+
{
77+
$this->assertSame(2, $this->getMapping()->count());
78+
79+
$this->getMapping()->eq('id', 1)->remove();
80+
81+
$this->assertSame(1, $this->getMapping()->count());
82+
}
83+
7584
public function testInsert()
7685
{
7786
$customer = [

0 commit comments

Comments
 (0)