Skip to content

Commit b91ae1f

Browse files
committed
newModelQuery rename
1 parent 9ce8061 commit b91ae1f

File tree

6 files changed

+63
-71
lines changed

6 files changed

+63
-71
lines changed

src/Illuminate/Database/Eloquent/Builder.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ public function whereKeyNot($id)
219219
public function where($column, $operator = null, $value = null, $boolean = 'and')
220220
{
221221
if ($column instanceof Closure) {
222-
$query = $this->model->newUneagerQueryWithoutScopes();
223-
224-
$column($query);
222+
$column($query = $this->model->newModelQuery());
225223

226224
$this->query->addNestedWhereQuery($query->getQuery(), $boolean);
227225
} else {

src/Illuminate/Database/Eloquent/Model.php

+16-21
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ public function push()
530530
*/
531531
public function save(array $options = [])
532532
{
533-
$query = $this->newUneagerQueryWithoutScopes();
533+
$query = $this->newModelQuery();
534534

535535
// If the "saving" event returns false we'll bail out of the save and return
536536
// false, indicating that the save failed. This provides a chance for any
@@ -815,7 +815,7 @@ public function forceDelete()
815815
*/
816816
protected function performDeleteOnModel()
817817
{
818-
$this->setKeysForSaveQuery($this->newUneagerQueryWithoutScopes())->delete();
818+
$this->setKeysForSaveQuery($this->newModelQuery())->delete();
819819

820820
$this->exists = false;
821821
}
@@ -840,6 +840,18 @@ public function newQuery()
840840
return $this->registerGlobalScopes($this->newQueryWithoutScopes());
841841
}
842842

843+
/**
844+
* Get a new query builder that doesn't have any global scopes or eager loading.
845+
*
846+
* @return \Illuminate\Database\Eloquent\Builder|static
847+
*/
848+
public function newModelQuery()
849+
{
850+
return $this->newEloquentBuilder(
851+
$this->newBaseQueryBuilder()
852+
)->setModel($this);
853+
}
854+
843855
/**
844856
* Get a new query builder with no relationships loaded.
845857
*
@@ -874,26 +886,11 @@ public function registerGlobalScopes($builder)
874886
*/
875887
public function newQueryWithoutScopes()
876888
{
877-
return $this->newUneagerQueryWithoutScopes()
889+
return $this->newModelQuery()
878890
->with($this->with)
879891
->withCount($this->withCount);
880892
}
881893

882-
/**
883-
* Get a new query builder that doesn't have any global scopes or eager loading.
884-
*
885-
* @return \Illuminate\Database\Eloquent\Builder|static
886-
*/
887-
public function newUneagerQueryWithoutScopes()
888-
{
889-
$builder = $this->newEloquentBuilder($this->newBaseQueryBuilder());
890-
891-
// Once we have the query builders, we will set the model instances so the
892-
// builder can easily access any information it may need from the model
893-
// while it is constructing and executing various queries against it.
894-
return $builder->setModel($this);
895-
}
896-
897894
/**
898895
* Get a new query instance without a given scope.
899896
*
@@ -902,9 +899,7 @@ public function newUneagerQueryWithoutScopes()
902899
*/
903900
public function newQueryWithoutScope($scope)
904901
{
905-
$builder = $this->newQuery();
906-
907-
return $builder->withoutGlobalScope($scope);
902+
return $this->newQuery()->withoutGlobalScope($scope);
908903
}
909904

910905
/**

src/Illuminate/Database/Eloquent/SoftDeletes.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function performDeleteOnModel()
4949
if ($this->forceDeleting) {
5050
$this->exists = false;
5151

52-
return $this->newUneagerQueryWithoutScopes()->where($this->getKeyName(), $this->getKey())->forceDelete();
52+
return $this->newModelQuery()->where($this->getKeyName(), $this->getKey())->forceDelete();
5353
}
5454

5555
return $this->runSoftDelete();
@@ -62,7 +62,7 @@ protected function performDeleteOnModel()
6262
*/
6363
protected function runSoftDelete()
6464
{
65-
$query = $this->newUneagerQueryWithoutScopes()->where($this->getKeyName(), $this->getKey());
65+
$query = $this->newModelQuery()->where($this->getKeyName(), $this->getKey());
6666

6767
$time = $this->freshTimestamp();
6868

tests/Database/DatabaseEloquentBuilderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public function testNestedWhere()
575575
$nestedRawQuery = $this->getMockQueryBuilder();
576576
$nestedQuery->shouldReceive('getQuery')->once()->andReturn($nestedRawQuery);
577577
$model = $this->getMockModel()->makePartial();
578-
$model->shouldReceive('newUneagerQueryWithoutScopes')->once()->andReturn($nestedQuery);
578+
$model->shouldReceive('newModelQuery')->once()->andReturn($nestedQuery);
579579
$builder = $this->getBuilder();
580580
$builder->getQuery()->shouldReceive('from');
581581
$builder->setModel($model);

0 commit comments

Comments
 (0)