diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ed60e6..d507a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.9.2 + +* fix(orm): `getQueryBuilder()` now clones the query builder +* feat(orm): add `withQueryBuilder()` + ## 0.9.1 * fix: static analysis problem with assignment of empty `ArrayCollection` to diff --git a/packages/collections-orm/src/QueryPageable.php b/packages/collections-orm/src/QueryPageable.php index 6bafa99..876d306 100644 --- a/packages/collections-orm/src/QueryPageable.php +++ b/packages/collections-orm/src/QueryPageable.php @@ -76,7 +76,7 @@ public function withItemsPerPage(int $itemsPerPage): static final public function getQueryBuilder(): QueryBuilder { - return $this->queryBuilder; + return clone $this->queryBuilder; } /** @@ -91,6 +91,14 @@ final public function updateQueryBuilder(\Closure $function): static return $instance; } + final protected function withQueryBuilder(QueryBuilder $queryBuilder): static + { + $instance = clone $this; + $instance->queryBuilder = $queryBuilder; + + return $instance; + } + /** * @return self */ diff --git a/packages/collections-orm/src/QueryRecollection.php b/packages/collections-orm/src/QueryRecollection.php index b783ff6..0bcf6b1 100644 --- a/packages/collections-orm/src/QueryRecollection.php +++ b/packages/collections-orm/src/QueryRecollection.php @@ -109,7 +109,7 @@ public function withItemsPerPage(int $itemsPerPage): static final public function getQueryBuilder(): QueryBuilder { - return $this->queryBuilder; + return clone $this->queryBuilder; } /** @@ -124,6 +124,14 @@ final public function updateQueryBuilder(\Closure $function): static return $instance; } + final protected function withQueryBuilder(QueryBuilder $queryBuilder): static + { + $instance = clone $this; + $instance->queryBuilder = $queryBuilder; + + return $instance; + } + /** * @return self */