Dear All,
I am trying to make pagination workable in my web application. But it seems not not giving me correct number for totalCount properties. My code is-
$find_query = "SELECT * FROM business WHERE status='Enabled' ";
$query = Business::findBySql($find_query);
//$query = Business::find()->where(['status' => 'Enabled']);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 10]);
$data_rows = $query->offset($pages->offset)
->limit($pages->limit)
->all();
From above code, if I use object with findBySql() then it’s giving me right number of rows but then the number of rows is not matching with $pages->totalCount value. totalCount giving me different number than actual result rows number.
If use commented object with find() then its giving me same row number for $pages->totalCount and $data_rows.
What I need to update here to make sure findBySql() is working as expected?
I have to use findBySql() because my SQL is little bit complex which contains multiple join operation.
Advance thanks…