public function getCarName() { $name = ''; if ($this->brand_id) { $name = $name . ' ' . AutoBrands::findOne($this->brand_id)->name; } if ($this->model_id) { $name = $name . ' ' . AutoModels::findOne($this->model_id)->name; } if (empty($name)) { $name = $this->name; } if ($this->year) { $name = $name . ' ' . $this->year . 'г.'; } return $name; }
/** * @return \yii\db\ActiveQuery */ public function getAutoModels() { return $this->hasMany(AutoModels::className(), ['brand_id' => 'id']); }