Pagination issue after upgrading to 2.0.50
fejan-malek opened this issue · comments
What steps will reproduce the problem?
- Create a simple CRUD.
- From search return all the records and from controller pass parameters for a filter like employee_id.
What is the expected result?
It must return data that is related to the particular employee documents only.
What do you get instead?
It returns 2 data in Gridview but the count is for all the employee-related documents.
Additional info
Q | A |
---|---|
Yii version | 2.0.50? |
PHP version | 8.0.25 |
Operating system | Mac OS |
![Screenshot 2024-06-05 at 12 59 31 PM](https://private-user-images.githubusercontent.com/63099555/336731654-255799ab-1c5c-4e2e-9405-d96232f768e7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgzMzI2NTEsIm5iZiI6MTcxODMzMjM1MSwicGF0aCI6Ii82MzA5OTU1NS8zMzY3MzE2NTQtMjU1Nzk5YWItMWM1Yy00ZTJlLTk0MDUtZDk2MjMyZjc2OGU3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE0VDAyMzIzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI1MWJmOTIzZjQxNmRkN2IwYTA4NDk0ODhiZWQ3NjE2YzU0MTIyMGI2ODZjNDc1MzA1NDBhODkwN2I2MzE4NzImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.zSfhTv7gvPtcVI3cv8PwSv3dPG2z2TFFbRhqnKtYaac)
Below is my search function look like.
public function search($params)
{
$query = EmployeePayslip::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]],
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$dataProvider->pagination->pageSize = $this->pageSize ?? Yii::$app->params['pageSize'];
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'employee_id' => $this->employee_id,
'payslip_type' => $this->payslip_type,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'remark', $this->remark])
->andFilterWhere(['like', "DATE_FORMAT(pay_start_date, '%d-%m-%Y')", $this->pay_start_date])
->andFilterWhere(['like', "DATE_FORMAT(pay_end_date, '%d-%m-%Y')", $this->pay_end_date])
->andFilterWhere(['like', 'payslip_no', $this->payslip_no]);
return $dataProvider;
}
Well it looks like there is much much bigger problem with the new update. I bricked my whole CMS. Searching is broken but also saving of every model screams errors like
...vendor\yiisoft\yii2\db\ActiveQueryTrait.php(181): yii\db\BaseActiveRecord->getRelation('admi_csrf')
or
...vendor\yiisoft\yii2\db\ActiveQueryTrait.php(181): yii\db\BaseActiveRecord->getRelation('id')
even though there are not such relations. I'm still collecting data and info but I thing you just discovered one output of a bigger problem with this update.
I updated the Yii ASAP because of the security fixes, but this situation is unfortunate.
I updated this version with my production project and there I identified the issue.
But now I am downgraded to 2.0.49.