Skip to content

Commit

Permalink
Merge pull request #104 from Rathil/master
Browse files Browse the repository at this point in the history
Fix for method count without specifying $criteria but with the condition in defaultScope
  • Loading branch information
Sammaye committed Aug 25, 2013
2 parents f2500ad + 025e002 commit 585ca50
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions EMongoDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,16 @@ public function saveCounters(array $counters,$lower=null,$upper=null) {
* Count() allows you to count all the documents returned by a certain condition, it is analogous
* to $db->collection->find()->count() and basically does exactly that...
* @param EMongoCriteria|array $criteria
* @return int
*/
public function count($criteria = array()){
$this->trace(__FUNCTION__);

// If we provide a manual criteria via EMongoCriteria or an array we do not use the models own DbCriteria
$criteria = !empty($criteria) || $criteria instanceof EMongoCriteria ? $criteria : $this->getDbCriteria();
if (is_array($criteria) && isset($criteria['condition'])){
$criteria = $criteria['condition'];
}
if($criteria instanceof EMongoCriteria)
$criteria = $criteria->getCondition();
return $this->getCollection()->find(isset($criteria) ? $criteria : array())->count();
Expand Down

0 comments on commit 585ca50

Please sign in to comment.