Skip to content

Commit 0b08a38

Browse files
committed
1 parent ddbf3f5 commit 0b08a38

File tree

3 files changed

+11
-33
lines changed

3 files changed

+11
-33
lines changed

src/Query/Builder.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -851,15 +851,6 @@ public function pluck($column, $key = null)
851851
{
852852
$results = $this->get($key === null ? [$column] : [$column, $key]);
853853

854-
// Convert ObjectID's to strings
855-
if (((string) $key) === '_id') {
856-
$results = $results->map(function ($item) {
857-
$item->_id = $item->id;
858-
859-
return $item;
860-
});
861-
}
862-
863854
$p = Arr::pluck($results, $column, $key);
864855

865856
return new Collection($p);

tests/Query/BuilderTest.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,28 +1573,4 @@ private static function getBuilder(): Builder
15731573

15741574
return new Builder($connection, null, $processor);
15751575
}
1576-
1577-
public function testPluckObjectId()
1578-
{
1579-
DB::table('users')->insert([
1580-
['_id' => $id = new \MongoDB\BSON\ObjectId(), 'name' => 'Jane Doe', 'age' => 20],
1581-
]);
1582-
1583-
$names = DB::table('users')->pluck('name', '_id')->toArray();
1584-
$this->assertCount(1, $names);
1585-
$this->assertArrayHasKey((string) $id, $names);
1586-
$this->assertEquals([(string) $id => 'Jane Doe'], $names);
1587-
}
1588-
1589-
public function testPluckObjectIdWithIdAlias()
1590-
{
1591-
DB::table('users')->insert([
1592-
['_id' => $id = new \MongoDB\BSON\ObjectId(), 'name' => 'Jane Doe', 'age' => 20],
1593-
]);
1594-
1595-
$names = DB::table('users')->pluck('name', 'id')->toArray();
1596-
$this->assertCount(1, $names);
1597-
$this->assertArrayHasKey((string) $id, $names);
1598-
$this->assertEquals([(string) $id => 'Jane Doe'], $names);
1599-
}
16001576
}

tests/QueryBuilderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,17 @@ public function testPluck()
525525
$this->assertEquals([25], $age);
526526
}
527527

528+
public function testPluckObjectId()
529+
{
530+
$id = new ObjectId();
531+
DB::table('users')->insert([
532+
['id' => $id, 'name' => 'Jane Doe'],
533+
]);
534+
535+
$names = DB::table('users')->pluck('name', 'id')->toArray();
536+
$this->assertEquals([(string) $id => 'Jane Doe'], $names);
537+
}
538+
528539
public function testList()
529540
{
530541
DB::table('items')->insert([

0 commit comments

Comments
 (0)