Skip to content

Commit 1df706f

Browse files
committed
Use toBase to properly apply scopes
1 parent 1724660 commit 1df706f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Query/Model/Builder.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected function callScope(callable $scope, array $parameters = []): static
136136
*/
137137
public function chunk(int $pageSize, Closure $callback, bool $isCritical = false, bool $isolate = false): bool
138138
{
139-
return $this->query->chunk($pageSize, function (array $records) use ($callback) {
139+
return $this->toBase()->chunk($pageSize, function (array $records) use ($callback) {
140140
return $callback($this->model->hydrate($records));
141141
}, $isCritical, $isolate);
142142
}
@@ -147,7 +147,7 @@ public function chunk(int $pageSize, Closure $callback, bool $isCritical = false
147147
public function paginate(int $pageSize = 1000, bool $isCritical = false): Collection
148148
{
149149
return $this->model->hydrate(
150-
$this->query->paginate(...func_get_args())
150+
$this->toBase()->paginate(...func_get_args())
151151
);
152152
}
153153

@@ -156,7 +156,7 @@ public function paginate(int $pageSize = 1000, bool $isCritical = false): Collec
156156
*/
157157
public function slice(int $page = 1, int $perPage = 100, string $orderBy = 'cn', string $orderByDir = 'asc'): Slice
158158
{
159-
$slice = $this->query->slice(...func_get_args());
159+
$slice = $this->toBase()->slice(...func_get_args());
160160

161161
$models = $this->model->hydrate($slice->items());
162162

@@ -174,7 +174,7 @@ public function slice(int $page = 1, int $perPage = 100, string $orderBy = 'cn',
174174
public function forPage(int $page = 1, int $perPage = 100, string $orderBy = 'cn', string $orderByDir = 'asc'): Collection
175175
{
176176
return $this->model->hydrate(
177-
$this->query->forPage(...func_get_args())
177+
$this->toBase()->forPage(...func_get_args())
178178
);
179179
}
180180

@@ -424,7 +424,7 @@ public function findByGuidOrFail(string $guid, array|string $selects = ['*']): M
424424
*/
425425
public function toBase(): QueryBuilder
426426
{
427-
return $this->applyScopes()->query;
427+
return $this->applyScopes()->getQuery();
428428
}
429429

430430
/**
@@ -748,7 +748,9 @@ public function notFilter(Closure $closure): static
748748
$query = $this->newNestedModelInstance($closure);
749749

750750
return $this->rawFilter(
751-
$this->query->getGrammar()->compileNot($query->getQuery()->getQuery())
751+
$this->query->getGrammar()->compileNot(
752+
$query->getQuery()->getQuery()
753+
)
752754
);
753755
}
754756

0 commit comments

Comments
 (0)