Filtrado de visión de gridview yii2 en una columna relacional
class UserSearch extends User
{
public $company_name;
public function rules()
{
return [
[['first_name', 'last_name', 'email', 'company_name'], 'safe']
];
}
public function search()
{
$query = User::find();
$query->joinWith(['client c']); //set relation alias
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query
->andFilterWhere(['like', 'first_name', $this->first_name])
->andFilterWhere(['like', 'last_name', $this->last_name])
->andFilterWhere(['like', 'email', $this->email])
->andFilterWhere(['like', "c.company_name", $this->company_name]);
return $dataProvider;
}
}
Mysterious Macaque