// Add groupby.
if ($groupby) { foreach ($groupby as $field) { // Handle group by of field without table alias to avoid ambiguous
// column error.
if ($field ==
$this->view->storage->
get('base_field'
)) { $field =
$this->view->storage->
get('base_table'
) . '.' .
$field;
} $query->
groupBy($field);
} if (!
empty($this->having
) &&
$condition =
$this->
buildCondition('having'
)) { $query->
havingCondition($condition);
} } if (!
$this->getCountOptimized
) { // we only add the orderby if we're not counting.
if ($this->orderby
) { foreach ($this->orderby
as $order) { if ($order['field'
] == 'rand_'
) { $query->
orderRandom();
}