should be `$query->func()->avg('rating')`