Commit 11634993 authored by Jens's avatar Jens

Allowed query chaining

parent a6d0537e
...@@ -24,7 +24,8 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -24,7 +24,8 @@ class Query extends \Illuminate\Database\Query\Builder {
'>' => '$gt', '>' => '$gt',
'>=' => '$gte', '>=' => '$gte',
'in' => '$in', 'in' => '$in',
'exists' => '$exists' 'exists' => '$exists',
'or' => '$or',
); );
/** /**
...@@ -213,7 +214,7 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -213,7 +214,7 @@ class Query extends \Illuminate\Database\Query\Builder {
$wheres = array(); $wheres = array();
foreach ($this->wheres as $where) foreach ($this->wheres as $i=>$where)
{ {
// Convert id's // Convert id's
if ($where['column'] == '_id') if ($where['column'] == '_id')
...@@ -221,12 +222,19 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -221,12 +222,19 @@ class Query extends \Illuminate\Database\Query\Builder {
$where['value'] = ($where['value'] instanceof MongoID) ? $where['value'] : new MongoID($where['value']); $where['value'] = ($where['value'] instanceof MongoID) ? $where['value'] : new MongoID($where['value']);
} }
// First item of chain
if ($i == 0 && count($this->wheres) > 1)
{
// Copy over boolean value of next item in chain
$where['boolean'] = $this->wheres[$i+1]['boolean'];
}
// Delegate // Delegate
$method = "compileWhere{$where['type']}"; $method = "compileWhere{$where['type']}";
$compiled = $this->{$method}($where); $compiled = $this->{$method}($where);
foreach ($compiled as $key=>$value) // Merge compiled where
$wheres[$key] = $value; $wheres = array_merge_recursive($wheres, $compiled);
} }
return $wheres; return $wheres;
...@@ -236,21 +244,27 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -236,21 +244,27 @@ class Query extends \Illuminate\Database\Query\Builder {
{ {
extract($where); extract($where);
// Convert operators
if (!isset($operator) || $operator == '=') if (!isset($operator) || $operator == '=')
{ {
return array($column => $value); $query = array($column => $value);
} }
else else
{ {
return array($column => array($this->conversion[$operator] => $value)); $query = array($column => array($this->conversion[$operator] => $value));
} }
if ($boolean == 'or')
{
return array($this->conversion[$boolean] => array($query));
}
return $query;
} }
public function compileWhereIn($where) public function compileWhereIn($where)
{ {
extract($where); extract($where);
return array($column => array($this->conversion['in'] => $values)); return array($column => array($this->conversion['in'] => $values));
} }
......
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