From 95a93115a91af8696530ba95fd4a59332c3e66ec Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Mon, 8 Jul 2024 22:06:25 +0700 Subject: [PATCH] refactor: `CriteriaPageable`, `CriteriaRecollection`, `MinimalCriteriaRecollection` now respect default order by (#112) --- CHANGELOG.md | 2 ++ packages/collections-domain/src/CriteriaPageable.php | 3 +-- packages/collections-domain/src/CriteriaRecollection.php | 2 +- .../collections-domain/src/MinimalCriteriaRecollection.php | 3 +-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bffac0c..2450e10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ * refactor: consolidate util classes * feat: default indexBy * feat: repositories now automatically detect indexBy +* refactor: `CriteriaPageable`, `CriteriaRecollection`, `MinimalCriteriaRecollection` + now respect default order by ## 0.8.0 diff --git a/packages/collections-domain/src/CriteriaPageable.php b/packages/collections-domain/src/CriteriaPageable.php index 754698b..3f80df7 100644 --- a/packages/collections-domain/src/CriteriaPageable.php +++ b/packages/collections-domain/src/CriteriaPageable.php @@ -14,7 +14,6 @@ namespace Rekalogika\Domain\Collections; use Doctrine\Common\Collections\Criteria; -use Doctrine\Common\Collections\Order; use Doctrine\Common\Collections\ReadableCollection; use Doctrine\Common\Collections\Selectable; use Rekalogika\Contracts\Collections\Exception\UnexpectedValueException; @@ -81,7 +80,7 @@ final private function __construct( $criteria = clone ($criteria ?? Criteria::create()); if (\count($criteria->orderings()) === 0) { - $criteria->orderBy(['id' => Order::Descending]); + $criteria->orderBy(Configuration::$defaultOrderBy); } $this->criteria = $criteria; diff --git a/packages/collections-domain/src/CriteriaRecollection.php b/packages/collections-domain/src/CriteriaRecollection.php index f292245..1fee32e 100644 --- a/packages/collections-domain/src/CriteriaRecollection.php +++ b/packages/collections-domain/src/CriteriaRecollection.php @@ -99,7 +99,7 @@ final private function __construct( $criteria = clone ($criteria ?? Criteria::create()); if (\count($criteria->orderings()) === 0) { - $criteria->orderBy(['id' => Order::Descending]); + $criteria->orderBy(Configuration::$defaultOrderBy); } $this->criteria = $criteria; diff --git a/packages/collections-domain/src/MinimalCriteriaRecollection.php b/packages/collections-domain/src/MinimalCriteriaRecollection.php index 5f5e1af..8789081 100644 --- a/packages/collections-domain/src/MinimalCriteriaRecollection.php +++ b/packages/collections-domain/src/MinimalCriteriaRecollection.php @@ -14,7 +14,6 @@ namespace Rekalogika\Domain\Collections; use Doctrine\Common\Collections\Criteria; -use Doctrine\Common\Collections\Order; use Doctrine\Common\Collections\ReadableCollection; use Doctrine\Common\Collections\Selectable; use Rekalogika\Contracts\Collections\Exception\UnexpectedValueException; @@ -82,7 +81,7 @@ final private function __construct( $criteria = clone ($criteria ?? Criteria::create()); if (\count($criteria->orderings()) === 0) { - $criteria->orderBy(['id' => Order::Descending]); + $criteria->orderBy(Configuration::$defaultOrderBy); } $this->criteria = $criteria;