Commit 25a8bacf authored by Jens Segers's avatar Jens Segers

Add elemMatch operator

parent d78e126c
......@@ -27,7 +27,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
'=', '<', '>', '<=', '>=', '<>', '!=',
'like', 'not like', 'between', 'ilike',
'&', '|', '^', '<<', '>>',
'exists', 'type', 'mod', 'where', 'all', 'size', 'regex',
'exists', 'type', 'mod', 'where', 'all', 'size', 'regex', 'elemmatch'
);
/**
......@@ -678,6 +678,12 @@ class Builder extends \Illuminate\Database\Query\Builder {
if (isset($where['operator']))
{
$where['operator'] = strtolower($where['operator']);
// Fix elemMatch
if ($where['operator'] == 'elemmatch')
{
$where['operator'] = 'elemMatch';
}
}
// Convert id's
......
......@@ -532,6 +532,27 @@ class QueryBuilderTest extends TestCase {
$results = DB::collection('users')->where('name', 'REGEX', $regex)->get();
$this->assertEquals(2, count($results));
DB::collection('users')->insert(array(
array(
'name' => 'John Doe',
'addresses' => array(
array('city' => 'Ghent'),
array('city' => 'Paris')
)
),
array(
'name' => 'Jane Doe',
'addresses' => array(
array('city' => 'Brussels'),
array('city' => 'Paris')
)
)
));
$users = DB::collection('users')->where('addresses', 'elemMatch', array('city' => 'Brussels'))->get();
$this->assertEquals(1, count($users));
$this->assertEquals('Jane Doe', $users[0]['name']);
}
public function testIncrement()
......
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