2016-11-15 5 views
0

Ich habe Car Modell mit Bezug auf Brand Modell von brand-id:Was mache ich falsch, wenn ich eine Beziehung suche?

public function getBrand() { 
return $this->hasOne(Brand::className(), [ 
    'id' => 'brand_id' 
]); 
} 

Marke Modell Name Feld hat. Und ich möchte nach diesem Feld suchen. Ich tue dies:

$query->joinWith('brand'); 
    $query->orFilterWhere([ 
    'like', 'brand.name', '%'.$this->company.'%', false 
]); 

von company Feld Suchen.

Marke Modell table_name ist car_brand

Was mache ich falsch?

Antwort

0

auf diese Weise versuchen

$query->joinWith(['brand' => function ($q) { 
     $q->where('tbl_brand.name LIKE "%' . $this->company . '%"'); 
}]);