Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 93b2114

Browse files
committed
Leaving glocal scopes to be applied by Eloquent
Closes #245 and finally fixes #281 newQuery() is used to both create a Builder and apply scopes. This was being overridden so we could use our own Builder, but it brings more tasks inside the same overridden method. Thus, we now override newQueryWithoutScopes() that is indeed the main builder-instantiator, and leave scopes for Eloquent.
1 parent 41c4be5 commit 93b2114

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/Ardent/Ardent.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Illuminate\Container\Container;
55
use Illuminate\Database\Capsule\Manager as DatabaseCapsule;
66
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7+
use Illuminate\Database\Eloquent\Relations\Relation;
78
use Illuminate\Events\Dispatcher;
89
use Illuminate\Hashing\BcryptHasher;
910
use Illuminate\Support\MessageBag;
@@ -386,7 +387,7 @@ protected function handleRelationalArray($relationName) {
386387
*
387388
* @param string $method
388389
* @param array $parameters
389-
* @return mixed
390+
* @return Relation|Builder|mixed
390391
*/
391392
public function __call($method, $parameters) {
392393
if (array_key_exists($method, static::$relationsData)) {
@@ -935,21 +936,16 @@ public static function find($id, $columns = array('*')) {
935936

936937
/**
937938
* Get a new query builder for the model's table.
938-
* Overriden from {@link \Model\Eloquent} to allow for usage of {@link throwOnFind}.
939+
* Overriden from {@link \Model\Eloquent} to allow for usage of {@link throwOnFind} in our {@link Builder}.
939940
*
940-
* @param bool $excludeDeleted
941+
* @see Model::newQueryWithoutScopes()
941942
* @return \Illuminate\Database\Eloquent\Builder
942943
*/
943-
public function newQuery($excludeDeleted = true) {
944+
public function newQueryWithoutScopes() {
944945
$builder = new Builder($this->newBaseQueryBuilder());
945946
$builder->throwOnFind = static::$throwOnFind;
946947

947-
// Once we have the query builders, we will set the model instances so the
948-
// builder can easily access any information it may need from the model
949-
// while it is constructing and executing various queries against it.
950-
$builder->setModel($this)->with($this->with);
951-
952-
return $this->applyGlobalScopes($builder);
948+
return $builder->setModel($this)->with($this->with);
953949
}
954950

955951
/**

0 commit comments

Comments
 (0)