Skip to content

Commit 40b105d

Browse files
committed
add feature without test
1 parent 7e27e64 commit 40b105d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Kitar/Dynamodb/Model/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public function __call($method, $parameters)
374374
return $this->$method(...$parameters);
375375
}
376376

377-
if (! in_array($method, $allowedBuilderMethods)) {
377+
if (! in_array($method, $allowedBuilderMethods) && ! $this->hasNamedScope($method)) {
378378
static::throwBadMethodCallException($method);
379379
}
380380

src/Kitar/Dynamodb/Query/Builder.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,38 @@ public function __call($method, $parameters)
472472
return $this;
473473
}
474474

475+
if ($this->hasNamedScope($method)) {
476+
return $this->callNamedScope($method, $parameters);
477+
}
478+
475479
throw new BadMethodCallException('Call to undefined method ' . static::class . "::{$method}()");
476480
}
477481

482+
/**
483+
* Determine if the given model has a scope.
484+
*
485+
* @param string $scope
486+
*
487+
* @return bool
488+
*/
489+
public function hasNamedScope(string $scope): bool
490+
{
491+
return $this->model_class && (new $this->model_class)->hasNamedScope($scope);
492+
}
493+
494+
/**
495+
* Apply the given named scope on the current builder instance.
496+
*
497+
* @param string $scope
498+
* @param array $parameters
499+
*
500+
* @return mixed
501+
*/
502+
protected function callNamedScope(string $scope, array $parameters = [])
503+
{
504+
return (new $this->model_class)->callNamedScope($scope, array_merge([$this], $parameters));
505+
}
506+
478507
/**
479508
* @inheritdoc
480509
*/

0 commit comments

Comments
 (0)