我有Car
模型与Brand
模型通过brand-id
:
public function getBrand() {
return $this->hasOne(Brand::className(), [
'id' => 'brand_id'
]);
}
模型名称字段。我想通过这个域来搜索。我这样做:
$query->joinWith('brand');
$query->orFilterWhere([
'like', 'brand.name', '%'.$this->company.'%', false
]);
按company
字段搜索。
Brand model table_name is car_brand
我做错了什么?
试试这个
$query->joinWith(['brand' => function ($q) {
$q->where('tbl_brand.name LIKE "%' . $this->company . '%"');
}]);