From 93b2114f914dd801e6c5119dcfe604af7f73e22d Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Tue, 2 Feb 2016 19:26:36 -0200 Subject: [PATCH] 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. --- src/Ardent/Ardent.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Ardent/Ardent.php b/src/Ardent/Ardent.php index 694de9b..ba64236 100755 --- a/src/Ardent/Ardent.php +++ b/src/Ardent/Ardent.php @@ -4,6 +4,7 @@ use Illuminate\Container\Container; use Illuminate\Database\Capsule\Manager as DatabaseCapsule; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Events\Dispatcher; use Illuminate\Hashing\BcryptHasher; use Illuminate\Support\MessageBag; @@ -386,7 +387,7 @@ protected function handleRelationalArray($relationName) { * * @param string $method * @param array $parameters - * @return mixed + * @return Relation|Builder|mixed */ public function __call($method, $parameters) { if (array_key_exists($method, static::$relationsData)) { @@ -935,21 +936,16 @@ public static function find($id, $columns = array('*')) { /** * Get a new query builder for the model's table. - * Overriden from {@link \Model\Eloquent} to allow for usage of {@link throwOnFind}. + * Overriden from {@link \Model\Eloquent} to allow for usage of {@link throwOnFind} in our {@link Builder}. * - * @param bool $excludeDeleted + * @see Model::newQueryWithoutScopes() * @return \Illuminate\Database\Eloquent\Builder */ - public function newQuery($excludeDeleted = true) { + public function newQueryWithoutScopes() { $builder = new Builder($this->newBaseQueryBuilder()); $builder->throwOnFind = static::$throwOnFind; - // Once we have the query builders, we will set the model instances so the - // builder can easily access any information it may need from the model - // while it is constructing and executing various queries against it. - $builder->setModel($this)->with($this->with); - - return $this->applyGlobalScopes($builder); + return $builder->setModel($this)->with($this->with); } /**