diff --git a/src/Query.php b/src/Query.php index 0bf97cf..8754a5f 100644 --- a/src/Query.php +++ b/src/Query.php @@ -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 * @@ -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 * @@ -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)) {