Answer the question
In order to leave comments, you need to log in
How to do a column search from a relationship table?
I work with one model (table - Goods), in the linked table there is additional information about the product, for example, "serial number"
I display "serial names" through the getSerial method in the main model ($data->serial) in GridView::
widget search by model (linked table).
Tell me how you can pass conditions to $dataProvider so that he would search for the serial field (which is located in the Goods_info table and is associated with the Goods table by identifier)
UPD
Yii2 question
Answer the question
In order to leave comments, you need to log in
In the main model, create a public $serial property.
When submitting the search form, set this property to a value.
In the method itself where the $dataProvider is formed, as a rule, this is the search () method:
.....
$withArray = array();
if(!empty($this->serial)){
/*Имя связи допустим Goods_info*/
$withArray[0]='Goods_info';
$criteria->compare('Goods_info.serial', $this->serial);
}
.....
$criteria->with = $withArray;
.....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question