A
A
Alex Ershov2015-06-01 15:07:32
Yii
Alex Ershov, 2015-06-01 15:07:32

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

1 answer(s)
E
Evgeny Bukharev, 2015-06-01
@evgenybuckharev

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 question

Ask a Question

731 491 924 answers to any question