Skip to content

Commit 65fd254

Browse files
author
Pooya Parsa
committed
pluck with _id
1 parent 25a258a commit 65fd254

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,16 @@ public function pluck($column, $key = null)
577577
{
578578
$results = $this->get(is_null($key) ? [$column] : [$column, $key]);
579579

580-
return $this->useCollections ? $results->pluck($column, $key) : Arr::pluck($results, $column, $key);
580+
// Convert ObjectID's to strings
581+
if ($key == '_id') {
582+
$results = $results->map(function ($item) {
583+
$item['_id'] = (string) $item['_id'];
584+
return $item;
585+
});
586+
}
587+
588+
$p = Arr::pluck($results, $column, $key);
589+
return $this->useCollections ? new Collection($p) : $p;
581590
}
582591

583592
/**
@@ -632,20 +641,7 @@ public function truncate()
632641
*/
633642
public function lists($column, $key = null)
634643
{
635-
if ($key == '_id') {
636-
$results = new Collection($this->get([$column, $key]));
637-
638-
// Convert ObjectID's to strings so that lists can do its work.
639-
$results = $results->map(function ($item) {
640-
$item['_id'] = (string) $item['_id'];
641-
642-
return $item;
643-
});
644-
645-
return $results->pluck($column, $key)->all();
646-
}
647-
648-
return parent::pluck($column, $key);
644+
return $this->pluck($column, $key);
649645
}
650646

651647
/**

0 commit comments

Comments
 (0)