V
V
vitaly_742021-06-14 22:40:02
Yii
vitaly_74, 2021-06-14 22:40:02

How to convert a query to a Relation AR relationship in Yii2?

There is a request object:

(new ActiveQuery())
                        ->select('sum(`value`)/count(*)')
                        ->from('assessment')
                        ->where('video_id = video.id')
                        ->andWhere(['type' => 1])

where assessment is a table of video ratings, the
connection is made through video_id=> video.id
I would like to get such a connection:
$video->truth

public function getTruth(){
...
}

but I don't understand how to do it. in fact, the hasOne|hasMany methods also return ActiveQuery, but how to connect? thank.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question