Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class Query implements Filterable, LimitOffsetInterface, OrderByInterface, Pagin
/** @var Relation[] Relations to utilize (join) */
protected $utilize = [];

/** @var bool Whether to disable the default sorts of the model */
protected $disableDefaultSort = false;

/**
* Get the database connection
*
Expand Down Expand Up @@ -175,6 +178,32 @@ public function setFilter(Filter\Chain $filter)
return $this;
}

/**
* Disable default sorts
*
* Prevents the default sort rules of the source model from being used
*
* @param bool $disable
*
* @return $this
*/
public function disableDefaultSort($disable = true)
{
$this->disableDefaultSort = (bool) $disable;

return $this;
}

/**
* Get whether to not use the default sort rules of the source model
*
* @return bool
*/
public function defaultSortDisabled()
{
return $this->disableDefaultSort;
}

/**
* Set columns to select from the model
*
Expand Down Expand Up @@ -747,7 +776,10 @@ protected function groupColumnsByTarget(Generator $columns)
protected function order(Select $select)
{
$orderBy = $this->getOrderBy();
$defaultSort = (array) $this->getModel()->getDefaultSort();
$defaultSort = [];
if (! $this->defaultSortDisabled()) {
$defaultSort = (array) $this->getModel()->getDefaultSort();
}

if (empty($orderBy)) {
if (empty($defaultSort)) {
Expand Down