diff --git a/CHANGELOG.md b/CHANGELOG.md index e390a862..9a15636a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Yii Framework 2 Elasticsearch extension Change Log ----------------------- - Bug #344: Disabled JSON pretty print for ElasticSearch bulk API (rhertogh) +- Bug #350: Remove deprecated code, set $pagination->totalCount (lav45) 2.1.4 May 22, 2023 diff --git a/src/ActiveDataProvider.php b/src/ActiveDataProvider.php index d800bf0a..bb89f649 100644 --- a/src/ActiveDataProvider.php +++ b/src/ActiveDataProvider.php @@ -122,9 +122,6 @@ protected function prepareModels() if (is_array(($results = $query->search($this->db)))) { $this->setQueryResults($results); - if ($pagination !== false) { - $pagination->totalCount = $this->getTotalCount(); - } return $results['hits']['hits']; } $this->setQueryResults([]); diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 100dffbc..806daca7 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -138,4 +138,23 @@ public function testRefresh() $dataProvider->refresh(); $this->assertEquals(1, $dataProvider->getTotalCount()); } + + public function testTotalCountAfterSearch() + { + $query = Customer::find(); + $provider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSize' => 2, + ], + ]); + + $pagination = $provider->getPagination(); + $this->assertEquals(2, $pagination->getPageCount()); + $this->assertEquals(3, $pagination->getTotalCount()); + + $query->andWhere(['name' => 'user2']); + $this->assertEquals(1, $pagination->getPageCount()); + $this->assertEquals(1, $pagination->getTotalCount()); + } }