Answer the question
In order to leave comments, you need to log in
What am I doing wrong when searching through related tables?
There is a Car model with a link to the brand by brand-id:
public function getBrand()
{
return $this->hasOne(Brand::className(), [
'id' => 'brand_id'
]);
}
$query->joinWith('brand');
$query->orFilterWhere([
'like', 'brand.name', '%'.$this->company.'%', false
]);
Answer the question
In order to leave comments, you need to log in
1. You now have the name of the model, but the name of the table should be
2. The characters '%' Yii sets itself
$query->orFilterWhere([
'like', 'car_brand.name', $this->company
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question