Skip to content

Commit

Permalink
Fix to prevent recursive where clause addition for chunkById
Browse files Browse the repository at this point in the history
  • Loading branch information
soundsgoodsofar committed Nov 22, 2016
1 parent e2b2298 commit 4e56efc
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,24 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
return $this;
}

/**
* Adds an id limit to assist with Eloquent chunkById.
* Subsequent calls override existing limit.
*
* @param string $column
* @param integer $value
*/
protected function chunkIdWhere($column, $value)
{
$where = compact('column', 'value');
$where['type'] = 'Basic';
$where['operator'] = '>';
$where['boolean'] = 'and';
$this->wheres['chunkId'] = $where;

return $this;
}

/**
* Add an array of where clauses to the query.
*
Expand Down Expand Up @@ -1498,9 +1516,9 @@ public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
return $order['column'] === $column;
})->values()->all();

return $this->where($column, '>', $lastId)
->orderBy($column, 'asc')
->take($perPage);
return $this->chunkIdWhere($column, $lastId)
->orderBy($column, 'asc')
->take($perPage);
}

/**
Expand Down

0 comments on commit 4e56efc

Please sign in to comment.