diff --git a/src/ORM/DataQuery.php b/src/ORM/DataQuery.php index 7599ffac7b4..e909b217fb6 100644 --- a/src/ORM/DataQuery.php +++ b/src/ORM/DataQuery.php @@ -395,7 +395,12 @@ protected function ensureSelectContainsOrderbyColumns($query, $originalSelect = // format internally; then this check can be part of selectField() $selects = $query->getSelect(); if (!isset($selects[$col]) && !in_array($qualCol, $selects)) { - $query->selectField($qualCol); + // Use the original select if possible. + if (array_key_exists($col, $originalSelect)) { + $query->selectField($originalSelect[$col], $col); + } else { + $query->selectField($qualCol); + } } } else { $qualCol = '"' . implode('"."', $parts) . '"';