diff --git a/vendor/dipper/foundation/src/Repository/Repository.php b/vendor/dipper/foundation/src/Repository/Repository.php index 84833f13..a8536d58 100644 --- a/vendor/dipper/foundation/src/Repository/Repository.php +++ b/vendor/dipper/foundation/src/Repository/Repository.php @@ -619,6 +619,20 @@ abstract class Repository implements RepositoryInterface, CacheableInterface, Cr return $this->sync($id, $relation, $attributes, false); } + /** + * Add a generic "order by" clause if the query doesn't already have one. + * + * @return void + */ + public function enforceOrderBy() + { + if ($this->model instanceof EloquentBuilder) { + if (empty($this->model->getQuery()->orders) && empty($this->model->getQuery()->unionOrders)) { + $this->orderBy($this->getModel()->getQualifiedKeyName(), 'asc'); + } + } + } + /** * 返回空值 *