Commit e2a8fae1 authored by Dan Jones's avatar Dan Jones Committed by Jens Segers

Return proper value instead of _id on QueryBuilder (#1747)

Fixes #1741
parent cc66b3a8
......@@ -204,6 +204,16 @@ class Builder extends BaseBuilder
return $this->where('_id', '=', $this->convertKey($id))->first($columns);
}
/**
* @inheritdoc
*/
public function value($column)
{
$result = (array) $this->first([$column]);
return Arr::get($result, $column);
}
/**
* @inheritdoc
*/
......
......@@ -701,4 +701,16 @@ class QueryBuilderTest extends TestCase
$this->assertEquals(1, count($result['tags']));
}
}
public function testValue()
{
DB::collection('books')->insert([
['title' => 'Moby-Dick', 'author' => ['first_name' => 'Herman', 'last_name' => 'Melville']]
]);
$this->assertEquals('Moby-Dick', DB::collection('books')->value('title'));
$this->assertEquals(['first_name' => 'Herman', 'last_name' => 'Melville'], DB::collection('books')->value('author'));
$this->assertEquals('Herman', DB::collection('books')->value('author.first_name'));
$this->assertEquals('Melville', DB::collection('books')->value('author.last_name'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment