diff --git a/api/src/Storage.php b/api/src/Storage.php index 83f5934e08..7761aa1ca5 100644 --- a/api/src/Storage.php +++ b/api/src/Storage.php @@ -486,12 +486,6 @@ class Storage extends Storage\Base */ protected function process_search(&$criteria, &$only_keys=True, &$order_by='', &$extra_cols='', &$wildcard='', &$op='AND', &$filter=null, &$join='') { - // if no CFs are defined OR used and became unavailable (deleted or permissions changed) - if (!$this->customfields && strpos($order_by, self::CF_PREFIX) === false && - strpos(implode(',', array_keys($filter ? $filter : [])), self::CF_PREFIX) === false) - { - return; - } if ($only_keys === false) { $only_keys = $this->table_name.'.*'; @@ -588,6 +582,15 @@ class Storage extends Storage\Base { $col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col; } + // Check to make sure our order by doesn't have aliases that won't work + else if (stripos($col, 'AS') !== false && $order_by) + { + list($value, $alias) = explode(' AS ', $col); + if(stripos($order_by, $alias) !== FALSE) + { + $order_by = str_replace($alias, $value, $order_by); + } + } } } // check if we order by a custom field --> join cf table for given cf and order by it's value