Skip to content

Commit

Permalink
feat(orm): getQueryBuilder() now clones the query builder, add `wit…
Browse files Browse the repository at this point in the history
…hQueryBuilder()` (#124)
  • Loading branch information
priyadi authored Jul 13, 2024
1 parent 46e5fb5 commit eb38ace
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 9 additions & 1 deletion packages/collections-orm/src/QueryPageable.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function withItemsPerPage(int $itemsPerPage): static

final public function getQueryBuilder(): QueryBuilder
{
return $this->queryBuilder;
return clone $this->queryBuilder;
}

/**
Expand All @@ -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<TKey,T>
*/
Expand Down
10 changes: 9 additions & 1 deletion packages/collections-orm/src/QueryRecollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function withItemsPerPage(int $itemsPerPage): static

final public function getQueryBuilder(): QueryBuilder
{
return $this->queryBuilder;
return clone $this->queryBuilder;
}

/**
Expand All @@ -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<TKey,T>
*/
Expand Down

0 comments on commit eb38ace

Please sign in to comment.