Skip to content

Commit 070e275

Browse files
dplewisTomWFox
authored andcommitted
Add documentation for query.withCount (#645)
See parse-community/parse-php-sdk#448
1 parent 4973012 commit 070e275

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

_includes/js/queries.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ query.withCount();
7676
const response = await query.find(); // { results: [ GameScore, ... ], count: 200 }
7777
```
7878
⚠️ Сount operations can be slow and expensive.
79-
> If you only want to get the count without objects - use [Counting Objects](#counting-objects).
79+
80+
If you only want to get the count without objects - use [Counting Objects](#counting-objects).
8081

8182
For sortable types like numbers and strings, you can control the order in which results are returned:
8283

_includes/php/queries.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,32 @@ You can skip the first results by setting `skip`. In the old Parse hosted backen
6363
$query->skip(10); // skip the first 10 results
6464
```
6565

66+
### With Count
67+
68+
If you want to know the total number of rows in a table satisfying your query, for e.g. pagination purposes - you can use `withCount`.
69+
70+
**Note:** Using this feature will change the structure of response, see the example below.
71+
72+
Let's say you have 200 rows in a table called `GameScore`:
73+
74+
```php
75+
$query = new ParseQuery('GameScore');
76+
$query->withCount();
77+
$query->limit(25);
78+
79+
$response = $query->find();
80+
$response['count'] // Returns 200 the total number of objects dispite limit / skip
81+
$response['results'] // Returns 25 objects
82+
83+
// As of PHP 7.1 you can use Array Destructuring
84+
['count' => $count, 'results' => $results] = $query->find();
85+
86+
// Use $count and $results
87+
```
88+
⚠️ Сount operations can be slow and expensive.
89+
90+
If you only want to get the count without objects - use [Counting Objects](#counting-objects).
91+
6692
### Ascending and Descending
6793

6894
For sortable types like numbers and strings, you can control the order in which results are returned:

0 commit comments

Comments
 (0)