Permalink
Browse files

formatting

  • Loading branch information...
taylorotwell committed May 3, 2018
1 parent 5739f74 commit 5d3d98a8c620458b9c1f80fbcefa1d88f9490784
Showing with 45 additions and 49 deletions.
  1. +45 −49 src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
@@ -245,36 +245,6 @@ public function updateOrCreate(array $attributes, array $values = [])
return $instance;
}
/**
* Chunk the results of the query.
*
* @param int $count
* @param callable $callback
* @return bool
*/
public function chunk($count, callable $callback)
{
$builder = $this->getBuilder();
return $builder->chunk($count,$callback);
}
/**
* Execute a callback over each item while chunking.
*
* @param callable $callback
* @param int $count
* @return bool
*/
public function each(callable $callback, $count = 1000)
{
return $this->chunk($count, function ($results) use ($callback) {
foreach ($results as $key => $value) {
if ($callback($value, $key) === false) {
return false;
}
}
});
}
/**
* Execute the query and get the first related model.
@@ -384,7 +354,8 @@ public function getResults()
*/
public function get($columns = ['*'])
{
$builder = $this->getBuilder($columns);
$builder = $this->prepareQueryBuilder($columns);
$models = $builder->getModels();
// If we actually found models we will also eager load any relationships that
@@ -444,6 +415,49 @@ protected function shouldSelect(array $columns = ['*'])
return array_merge($columns, [$this->getQualifiedFirstKeyName()]);
}
/**
* Chunk the results of the query.
*
* @param int $count
* @param callable $callback
* @return bool
*/
public function chunk($count, callable $callback)
{
return $this->prepareQueryBuilder()->chunk($count,$callback);
}
/**
* Execute a callback over each item while chunking.
*
* @param callable $callback
* @param int $count
* @return bool
*/
public function each(callable $callback, $count = 1000)
{
return $this->chunk($count, function ($results) use ($callback) {
foreach ($results as $key => $value) {
if ($callback($value, $key) === false) {
return false;
}
}
});
}
/**
* Prepare the query builder for query execution.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function prepareQueryBuilder($columns = ['*'])
{
return $this->query->applyScopes()->addSelect(
$this->shouldSelect($this->query->getQuery()->columns ? [] : $columns)
);
}
/**
* Add the constraints for a relationship query.
*
@@ -539,22 +553,4 @@ public function getQualifiedLocalKeyName()
{
return $this->farParent->qualifyColumn($this->localKey);
}
/**
* Add the proper select columns onto the query so it is run with the proper
* columns. and return a builder instance with the correct columns.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
private function getBuilder($columns = ['*']){
$columns = $this->query->getQuery()->columns ? [] : $columns;
$builder = $this->query->applyScopes();
return $builder->addSelect(
$this->shouldSelect($columns)
);
}
}

0 comments on commit 5d3d98a

Please sign in to comment.