8000 Return proper value instead of _id on QueryBuilder · goodevilgenius/laravel-mongodb@20c6093 · GitHub
[go: up one dir, main page]

Skip to content

Commit 20c6093

Browse files
author
Dan Jones
committed
Return proper value instead of _id on QueryBuilder
Fixes mongodb#1741
1 parent fdf7f67 commit 20c6093

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ public function find($id, $columns = [])
203203
return $this->where('_id', '=', $this->convertKey($id))->first($columns);
204204
}
205205

206+
/**
207+
* @inheritdoc
208+
*/
209+
public function value($column)
210+
{
211+
$result = (array) $this->first([$column]);
212+
213+
return Arr::get($result, $column);
214+
}
215+
206216
/**
207217
* @inheritdoc
208218
*/

tests/QueryBuilderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,16 @@ public function testProjections()
701701
$this->assertEquals(1, count($result['tags']));
702702
}
703703
}
704+
705+
public function testValue()
706+
{
707+
DB::collection('books')->insert([
708+
['title' => 'Moby-Dick', 'author' => ['first_name' => 'Herman', 'last_name' => 'Melville']]
709+
]);
710+
711+
$this->assertEquals('Moby-Dick', DB::collection('books')->value('title'));
712+
$this->assertEquals(['first_name' => 'Herman', 'last_name' => 'Melville'], DB::collection('books')->value('author'));
713+
$this->assertEquals('Herman', DB::collection('books')->value('author.first_name'));
714+
$this->assertEquals('Melville', DB::collection('books')->value('author.last_name'));
715+
}
704716
}

0 commit comments

Comments
 (0)
0