$query->
from('product_review'
);
$query->
leftJoin('product_review', 'product', 'product', 'product.id = product_review.product_id OR product.parent_id = product_review.product_id'
);
$query->
andWhere('product_review.status = 1'
);
$query->
andWhere('product.id IN (:ids) OR product.parent_id IN (:ids)'
);
$query->
andWhere('product.version_id = :version'
);
$query->
setParameter('version',
$versionId);
$query->
setParameter('ids', Uuid::
fromHexToBytesList($ids), ArrayParameterType::STRING
);
$query->
addGroupBy('IFNULL(product.parent_id, product.id)'
);
$averages =
$query->
executeQuery()->
fetchAllAssociative();
$query =
new RetryableQuery( $this->connection,
$this->connection->
prepare('UPDATE product SET rating_average = :average WHERE id = :id AND version_id = :version'
) );
foreach ($averages as $average) { $query->
execute([ 'average' =>
$average['average'
],
'id' =>
$average['id'
],
'version' =>
$versionId,
]);
} }