Commit a6d0537e authored by Jens's avatar Jens

Fixed operator bug

parent ffa1875a
...@@ -16,7 +16,7 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -16,7 +16,7 @@ class Query extends \Illuminate\Database\Query\Builder {
* *
* @var array * @var array
*/ */
protected $operators = array( protected $conversion = array(
'=' => '=', '=' => '=',
'!=' => '$ne', '!=' => '$ne',
'<' => '$lt', '<' => '$lt',
...@@ -215,6 +215,12 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -215,6 +215,12 @@ class Query extends \Illuminate\Database\Query\Builder {
foreach ($this->wheres as $where) foreach ($this->wheres as $where)
{ {
// Convert id's
if ($where['column'] == '_id')
{
$where['value'] = ($where['value'] instanceof MongoID) ? $where['value'] : new MongoID($where['value']);
}
// Delegate // Delegate
$method = "compileWhere{$where['type']}"; $method = "compileWhere{$where['type']}";
$compiled = $this->{$method}($where); $compiled = $this->{$method}($where);
...@@ -230,12 +236,6 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -230,12 +236,6 @@ class Query extends \Illuminate\Database\Query\Builder {
{ {
extract($where); extract($where);
// Convert id's
if ($column == '_id')
{
$value = ($value instanceof MongoID) ? $value : new MongoID($value);
}
// Convert operators // Convert operators
if (!isset($operator) || $operator == '=') if (!isset($operator) || $operator == '=')
{ {
...@@ -243,7 +243,7 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -243,7 +243,7 @@ class Query extends \Illuminate\Database\Query\Builder {
} }
else else
{ {
return array($column => array($this->operators[$operator] => $value)); return array($column => array($this->conversion[$operator] => $value));
} }
} }
...@@ -251,42 +251,21 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -251,42 +251,21 @@ class Query extends \Illuminate\Database\Query\Builder {
{ {
extract($where); extract($where);
// Convert id's return array($column => array($this->conversion['in'] => $values));
if ($column == '_id')
{
foreach ($values as &$value)
$value = ($value instanceof MongoID) ? $value : new MongoID($value);
}
return array($column => array($this->operators['in'] => $values));
} }
public function compileWhereNull($where) public function compileWhereNull($where)
{ {
extract($where); extract($where);
// Convert id's return array($column => array($this->conversion['exists'] => false));
if ($column == '_id')
{
foreach ($values as &$value)
$value = ($value instanceof MongoID) ? $value : new MongoID($value);
}
return array($column => array($this->operators['exists'] => false));
} }
public function compileWhereNotNull($where) public function compileWhereNotNull($where)
{ {
extract($where); extract($where);
// Convert id's return array($column => array($this->conversion['exists'] => true));
if ($column == '_id')
{
foreach ($values as &$value)
$value = ($value instanceof MongoID) ? $value : new MongoID($value);
}
return array($column => array($this->operators['exists'] => true));
} }
} }
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