/**
* If any attributes that were requested to be ordered by are not explicitly in the attribute selection, add them.
*
* @param array $attributes
* @param null|string $alias
* @return array
*/
protected function mergeOrderByAttributes(array $attributes, $alias = null)
{
if (!$this->isWildCardSelection() && !empty($this->orderBy)) {
$orderBy = $this->getAttributesForAlias(array_keys($this->orderBy), $alias);
foreach ($orderBy as $attribute) {
if (!in_array(MBString::strtolower($attribute), MBString::array_change_value_case($attributes))) {
$attributes[] = $attribute;
}
}
}
return $attributes;
}