Commit 2c95ab73 authored by Ditty's avatar Ditty

allow setting hint option on querybuilder

Co-Authored-By: 's avatarManan Jadhav <jadhavm@uwindsor.ca>
parent c25900b3
...@@ -384,10 +384,12 @@ class Builder extends BaseBuilder ...@@ -384,10 +384,12 @@ class Builder extends BaseBuilder
if ($this->limit) { if ($this->limit) {
$options['limit'] = $this->limit; $options['limit'] = $this->limit;
} }
if ($this->hint) {
$options['hint'] = $this->hint;
}
if ($columns) { if ($columns) {
$options['projection'] = $columns; $options['projection'] = $columns;
} }
// if ($this->hint) $cursor->hint($this->hint);
// Fix for legacy support, converts the results to arrays instead of objects. // Fix for legacy support, converts the results to arrays instead of objects.
$options['typeMap'] = ['root' => 'array', 'document' => 'array']; $options['typeMap'] = ['root' => 'array', 'document' => 'array'];
......
...@@ -737,4 +737,25 @@ class QueryBuilderTest extends TestCase ...@@ -737,4 +737,25 @@ class QueryBuilderTest extends TestCase
$this->assertEquals('Herman', DB::collection('books')->value('author.first_name')); $this->assertEquals('Herman', DB::collection('books')->value('author.first_name'));
$this->assertEquals('Melville', DB::collection('books')->value('author.last_name')); $this->assertEquals('Melville', DB::collection('books')->value('author.last_name'));
} }
public function testHintOptions()
{
DB::collection('items')->insert([
['name' => 'fork', 'tags' => ['sharp', 'pointy']],
['name' => 'spork', 'tags' => ['sharp', 'pointy', 'round', 'bowl']],
['name' => 'spoon', 'tags' => ['round', 'bowl']],
]);
$results = DB::collection('items')->hint(['$natural' => -1])->get();
$this->assertArraySubset(['name' => 'spoon'], $results[0]);
$this->assertArraySubset(['name' => 'spork'], $results[1]);
$this->assertArraySubset(['name' => 'fork'], $results[2]);
$results = DB::collection('items')->hint(['$natural' => 1])->get();
$this->assertArraySubset(['name' => 'spoon'], $results[2]);
$this->assertArraySubset(['name' => 'spork'], $results[1]);
$this->assertArraySubset(['name' => 'fork'], $results[0]);
}
} }
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