Goods
и Rating
связаны они так public function getRatings(){
return $this->hasMany(Rating::className(),['id_gods'=>'id']);
}
quantity
и общее количество записей и как это можно узнать ? $data = $model->getRatings()
->select('count(rating.*), SUM(rating.quantity)')
->alias('rating')
->createCommand()
->queryOne();
$ratings = $model->ratings;
$count = $sum = 0;
if (is_array($ratings)) {
$count = count($ratings);
foreach($ratings as $rating) {
$sum += (int) $rating->quantity;
}
}
echo $count, $sum;