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

Commit

Permalink
Leaving glocal scopes to be applied by Eloquent
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
igorsantos07 committed Feb 2, 2016
1 parent 41c4be5 commit 93b2114
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/Ardent/Ardent.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 93b2114

Please sign in to comment.