Skip to content

Commit

Permalink
Add equals operator to mongo criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
canni committed Nov 30, 2010
1 parent acc23d6 commit a4ae356
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions EMongoCriteria.php
Expand Up @@ -15,6 +15,7 @@ class EMongoCriteria extends CComponent
'exists' => '$exists',
'notExists' => '$exists',
'mod' => '$mod',
'equals' => '$$eq'
);

const SORT_ASC = 1;
Expand Down Expand Up @@ -91,10 +92,18 @@ public function mergeWith($criteria)

foreach($criteria->_conditions as $fieldName=>$conds)
{
if(!isset($this->_conditions[$fieldName]))
$this->_conditions[$fieldName] = array();
foreach($conds as $operator=>$value)
$this->_conditions[$fieldName][$operator] = $value;
if(
is_array($conds) &&
count(array_diff(array_keys($conds), array_values(self::$operators))) == 0
)
{
if(!isset($this->_conditions[$fieldName]))
$this->_conditions[$fieldName] = array();
foreach($conds as $operator=>$value)
$this->_conditions[$fieldName][$operator] = $value;
}
else
$this->_conditions[$fieldName] = $conds;
}

if(!empty($criteria->_limit))
Expand Down Expand Up @@ -235,9 +244,12 @@ public function sort($fieldName, $order)
*/
protected function addCond($fieldName, $op, $value)
{
if(!isset($this->_conditions[$fieldName]))
if(!isset($this->_conditions[$fieldName]) && $op != self::$operators['equals'])
$this->_conditions[$fieldName] = array();

$this->_conditions[$fieldName][$op] = $value;
if($op != self::$operators['equals'])
$this->_conditions[$fieldName][$op] = $value;
else
$this->_conditions[$fieldName] = $value;
}
}

0 comments on commit a4ae356

Please sign in to comment.