Skip to content

Remove Eloquent\Builder::chunkById() already having the correct id field in Laravel #2569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,6 @@ public function decrement($column, $amount = 1, array $extra = [])
return parent::decrement($column, $amount, $extra);
}

/**
* @inheritdoc
*/
public function chunkById($count, callable $callback, $column = '_id', $alias = null)
{
return parent::chunkById($count, $callback, $column, $alias);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted your response in GromNaN/laravel-mongodb#25 (comment).

I missed that the meaningful change here was removing the _id parameter default value, since Laravel now consults the configured primary key (laravel/framework#28065).

}

/**
* @inheritdoc
*/
Expand Down
8 changes: 4 additions & 4 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,12 +834,12 @@ public function testChunkById(): void
User::create(['name' => 'spork', 'tags' => ['sharp', 'pointy', 'round', 'bowl']]);
User::create(['name' => 'spoon', 'tags' => ['round', 'bowl']]);

$count = 0;
User::chunkById(2, function (EloquentCollection $items) use (&$count) {
$count += count($items);
$names = [];
User::chunkById(2, function (EloquentCollection $items) use (&$names) {
$names = array_merge($names, $items->pluck('name')->all());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noted your response in GromNaN/laravel-mongodb#25 (comment).

Not sure why I thought + concatenated instead of overwrote for numeric indexes. I certainly confused it with array_merge(), which is what we do need to use here 👍

});

$this->assertEquals(3, $count);
$this->assertEquals(['fork', 'spork', 'spoon'], $names);
}

public function testTruncateModel()
Expand Down