diff --git a/ActiveDataProvider.php b/ActiveDataProvider.php index d800bf0a..bb89f649 100644 --- a/ActiveDataProvider.php +++ b/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/composer.json b/composer.json index ca696bfa..526f4c45 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "yiisoft/yii2": "<=2.0.49", + "yiisoft/yii2": ">=2.0.50", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 6b6bad94..58c28386 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()); + } }