Unverified Commit 5454ac96 authored by Jens Segers's avatar Jens Segers Committed by GitHub

Merge pull request #1317 from DoSomething/chunkById-5.5

Fix issue with chunkById.
parents cf15156f 62611090
......@@ -143,6 +143,14 @@ class Builder extends EloquentBuilder
return parent::decrement($column, $amount, $extra);
}
/**
* @inheritdoc
*/
public function chunkById($count, callable $callback, $column = '_id', $alias = null)
{
return parent::chunkById($count, $callback, $column, $alias);
}
/**
* @inheritdoc
*/
......
......@@ -618,6 +618,28 @@ class Builder extends BaseBuilder
return $this->increment($column, -1 * $amount, $extra, $options);
}
/**
* @inheritdoc
*/
public function chunkById($count, callable $callback, $column = '_id', $alias = null)
{
return parent::chunkById($count, $callback, $column, $alias);
}
/**
* @inheritdoc
*/
public function forPageAfterId($perPage = 15, $lastId = 0, $column = '_id')
{
// When using ObjectIDs to paginate, we need to use a hex string as the
// "minimum" ID rather than the integer zero so the '$lt' query works.
if ($column === '_id' && $lastId === 0) {
$lastId = '000000000000000000000000';
}
return parent::forPageAfterId($perPage, $lastId, $column);
}
/**
* @inheritdoc
*/
......
......@@ -534,4 +534,18 @@ class ModelTest extends TestCase
$user->birthday = new DateTime('19 august 1989');
$this->assertEmpty($user->getDirty());
}
public function testChunkById()
{
User::create(['name' => 'fork', 'tags' => ['sharp', 'pointy']]);
User::create(['name' => 'spork', 'tags' => ['sharp', 'pointy', 'round', 'bowl']]);
User::create(['name' => 'spoon', 'tags' => ['round', 'bowl']]);
$count = 0;
User::chunkById(2, function ($items) use (&$count) {
$count += count($items);
});
$this->assertEquals(3, $count);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment