Skip to content

Commit

Permalink
add findAllByPk method to EMongoDocument
Browse files Browse the repository at this point in the history
to meet the needs of RESTFullMongoYii

needs tests added
  • Loading branch information
sheershoff committed Aug 15, 2013
1 parent 249a6e2 commit 7c29eab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions EMongoDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,16 @@ public function findAll($criteria=array(),$fields=array()){

/**
* Finds all records based on $pk
* @param mixed $pk String or array of pk values
* @param mixed $pk String, MongoID or array of strings or MongoID values (one can mix strings and MongoID in the array)
*/
public function findAllByPk($pk=array(),$fields=array()){
if(is_string($pk)){
return $this->find (array($this->primaryKey() => $pk),$fields);
return $this->find (array($this->primaryKey() => $this->getPrimaryKey($pk)),$fields);
}else if(is_array($pk)){
return $this->find (array($this->primaryKey() => array('$in' => array($pk))),$fields);
foreach($pk as $k=>$v){
$pk[$k] = $this->getPrimaryKey($v);
}
return $this->find (array($this->primaryKey() => array('$in' => $pk)),$fields);
}
}

Expand Down

0 comments on commit 7c29eab

Please sign in to comment.