RepositoryQuery: Allow to ignore any default sort rules

This commit is contained in:
Johannes Meyer 2015-06-25 15:49:09 +02:00
parent 39ea81ac7b
commit ca112af9ad

View File

@ -220,10 +220,11 @@ class RepositoryQuery implements QueryInterface, Iterator
*
* @param string $field The name of the column by which to sort the query's result
* @param string $direction The direction to use when sorting (asc or desc, default is asc)
* @param bool $ignoreDefault Whether to ignore any default sort rules if $field is given
*
* @return $this
*/
public function order($field = null, $direction = null)
public function order($field = null, $direction = null, $ignoreDefault = false)
{
$sortRules = $this->repository->getSortRules();
if ($field === null) {
@ -240,7 +241,7 @@ class RepositoryQuery implements QueryInterface, Iterator
if ($direction !== null || !array_key_exists('order', $sortColumns)) {
$sortColumns['order'] = $direction ?: static::SORT_ASC;
}
} elseif (array_key_exists($field, $sortRules)) {
} elseif (! $ignoreDefault && array_key_exists($field, $sortRules)) {
$sortColumns = $sortRules[$field];
if (! array_key_exists('columns', $sortColumns)) {
$sortColumns['columns'] = array($field);