当我通过关系进行搜索时,我做错了什么

  • 本文关键字:错了 关系 搜索 yii2
  • 更新时间 :
  • 英文 :


我有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 . '%"');
 }]);

最新更新