Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fixbug in pluck function #3168

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

Closed
fuyuki0511 wants to merge 1 commit into mongodb:5.x from fuyuki0511:patch-1
Closed

Conversation

@fuyuki0511
Copy link
Contributor

@fuyuki0511 fuyuki0511 commented Oct 4, 2024

Fix bug in pluck function.
Cannot use object of type stdClass as array

Checklist

  • Add tests and ensure they pass

Fix bug in pluck function.
Cannot use object of type stdClass as array
@fuyuki0511 fuyuki0511 requested a review from a team as a code owner October 4, 2024 08:21
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

Thank you @fuyuki0511 for contributing. I really appreciate.

Also, could you add a test in QueryBuilderTest. Something like this:

 public function testPluckObjectId()
 {
 DB::table('users')->insert([
 ['id' => $id = new ObjectId(), 'name' => 'Jane Doe', 'age' => 20],
 ]);
 $names = DB::table('users')->pluck('name', 'id')->toArray();
 $this->assertCount(1, $names);
 $this->assertArrayHasKey((string) $id, $names);
 $this->assertEquals([(string) $id => 'Jane Doe'], $names);
 }

if (((string) $key) === '_id') {
$results = $results->map(function ($item) {
$item['_id'] = (string) $item['_id'];
$item->_id = (string) $item->id;
Copy link
Member

@GromNaN GromNaN Oct 4, 2024

Choose a reason for hiding this comment

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

I think this piece of code can be removed as Arr::pluck already convert stringable key value into string. https://github.com/laravel/framework/blob/646520ad682d98b5211c6e26092259cfbe130b5c/src/Illuminate/Collections/Arr.php#L562

fuyuki0511 reacted with thumbs up emoji
Copy link
Member

GromNaN commented Oct 4, 2024

I see you created a new PR #3169. You could have pushed to the same branch to update this PR and keep the discussion in the same place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@GromNaN GromNaN GromNaN requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /