Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for query.withCount [PHP] #645

Merged
merged 1 commit into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion _includes/js/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ query.withCount();
const response = await query.find(); // { results: [ GameScore, ... ], count: 200 }
```
⚠️ Сount operations can be slow and expensive.
> If you only want to get the count without objects - use [Counting Objects](#counting-objects).

If you only want to get the count without objects - use [Counting Objects](#counting-objects).

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

Expand Down
26 changes: 26 additions & 0 deletions _includes/php/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ You can skip the first results by setting `skip`. In the old Parse hosted backen
$query->skip(10); // skip the first 10 results
```

### With Count

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`.

**Note:** Using this feature will change the structure of response, see the example below.

Let's say you have 200 rows in a table called `GameScore`:

```php
$query = new ParseQuery('GameScore');
$query->withCount();
$query->limit(25);

$response = $query->find();
$response['count'] // Returns 200 the total number of objects dispite limit / skip
$response['results'] // Returns 25 objects

// As of PHP 7.1 you can use Array Destructuring
['count' => $count, 'results' => $results] = $query->find();

// Use $count and $results
```
⚠️ Сount operations can be slow and expensive.

If you only want to get the count without objects - use [Counting Objects](#counting-objects).

### Ascending and Descending

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