Skip to content

Commit

Permalink
Merge pull request #2 from yarlson/master
Browse files Browse the repository at this point in the history
Fixes a notice in count and countBy methods
  • Loading branch information
micheleangioni authored May 30, 2018
2 parents 4912dc7 + f2aedea commit 374bb9e
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/PhalconRepositories/AbstractCollectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function getIn(string $whereInKey, array $whereIn = [], string $orderBy =

return $this->model->find($input);
}

/**
* Return the first ordered $limit records querying input parameters.
* $limit = 0 means no limits.
Expand Down Expand Up @@ -272,7 +272,7 @@ public function getInAndWhereByPage(int $page = 1, int $limit = 10, string $wher
}

return $this->model->find($input);
}
}

/**
* Return the first ordered $limit records querying input parameters.
Expand Down Expand Up @@ -726,15 +726,8 @@ public function truncate()
*/
public function count()
{
$aggregateArray = [
[
'$count' => 'number'
]
];

$result = $this->model::aggregate($aggregateArray);

return $result->toArray()[0]['number'];
return $this->countBy([]);
}

/**
Expand All @@ -759,9 +752,13 @@ public function countBy(array $match = [])
'$count' => 'number'
];

$result = $this->model::aggregate($aggregateArray);
$result = $this->model::aggregate($aggregateArray)->toArray();

if (count($result)) {
return $result[0]['number'];
}

return $result->toArray()[0]['number'];
return 0;
}

/**
Expand Down

0 comments on commit 374bb9e

Please sign in to comment.