Answer the question
In order to leave comments, you need to log in
How to set a composite field in a Yii2 relationship?
Good afternoon,
There was a need to get the hasMany relationship using a composite field:
/**
* Функция получения рейтинга компании
* @return integer
*/
public function getRating()
{
return $this->hasMany(Reviews::className(), ['chan_channel' => 'id'])->average('star');
}
Answer the question
In order to leave comments, you need to log in
/**
* Функция генерации строки идентификатора компании в таблице Review
* @return boolean
*/
public function getReview_id()
{
return 'company_id_'.$this->id;
}
/**
* Функция получения рейтинга компании
* @return integer
*/
public function getRating()
{
return $this->hasMany(Reviews::className(), ['chan_channel' => 'review_id'])->average('star');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question