Answer the question
In order to leave comments, you need to log in
How to get model with hasOne multiple times?
There is a model $panel it has a function
public function getCar()
{
return $this->hasOne(Car::className(), ['id' => 'car_id']);
}
public function getBrand()
{
return $this->hasOne(Brand::className(), [
'id' => $this->brand_id
]);
}
$model->car->brand->name
Getting unknown property: app\models\Car::4
Answer the question
In order to leave comments, you need to log in
change
public function getBrand()
{
return $this->hasOne(Brand::className(), [
'id' => $this->brand_id
]);
}
public function getBrand()
{
return $this->hasOne(Brand::className(), [
'id' => 'brand_id'
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question