Get number of records in class
dansinclair25 opened this issue · 2 comments
Hi Guys,
This isn't an issue per say, but I was wondering whether there's a way to return the total number of records in a class using the PHP Library?
I know I can set the Limit, but I have Classes with 40k records in and as far as I can see there's no way of seeing how many records are in the class.
Any ideas welcome.
Regards,
/Dan
Found a solution.
I think what I'm trying to do might be fairly unique. I needed to get the total number of records in a class and getCount wasn't working.
The problem was that I wasn't setting anything like 'where' on the query so _query in parseQuery.php would always be empty. Therefore it would only send the standard request.
Here's a new function I created to get around this;
public function dsCountFind(){
$urlParams = array();
if(!empty($this->_query)){
$urlParams['where'] = json_encode( $this->_query );
}
if(!empty($this->_include)){
$urlParams['include'] = implode(',',$this->_include);
}
if(!empty($this->_order)){
$urlParams['order'] = implode(',',$this->_order);
}
if(!empty($this->_limit) || $this->_limit == 0){
$urlParams['limit'] = $this->_limit;
}
if(!empty($this->_skip)){
$urlParams['skip'] = $this->_skip;
}
if($this->_count == 1){
$urlParams['count'] = '1';
}
$request = $this->request(array(
'method' => 'GET',
'requestUrl' => $this->_requestUrl,
'urlParams' => $urlParams,
));
return $request;
//}
}
I also had to alter the getCount() function like so;
public function getCount(){
$this->_count = 1;
$this->_limit = 0;
return $this->dsCountFind();
}
I'm new to PHP and Parse really so if there is a simpler way please post here, otherwise enjoy my workaround!
/Dan
Thanks! Very useful 👍