Answer the question
In order to leave comments, you need to log in
Why does Yii2 pagination consider related models?
Added work with the associated model to the search method. Everything works, but pagination counts related models too. I output like this(carNumbers.car_number')
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'class' => 'yii\grid\CheckboxColumn',
'name' => 'id'
],
'name',
'phone',
[
'attribute' => 'carNumbers.car_number',
'value' => function ($model) {
$car_numbers = '';
foreach ($model->carNumbers as $car_number){
if($car_numbers == ''){
$car_numbers = $car_number->car_number;
}else{
$car_numbers .= ' '.$car_number->car_number;
}
}
return $car_numbers;
},
],
$query->joinWith(['carNumbers']);
$query->andFilterWhere(['LIKE', 'carNumbers.car_number', $this->getAttribute('carNumbers.car_number')]);
Answer the question
In order to leave comments, you need to log in
you say that you are using carNumbers.car_number, but in the gridview method you have written (most likely) a connection by many, and the connection by many is being processed. everything seems to be logical.
If someone gets to this question with a similar problem, I’ll say that replacing joinWith with with solves it, but it breaks the search, I just finalized the search separately, I didn’t find how to solve the search problem within the framework itself, I made an additional request and just throw it in search preselected id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question