Skip to content

Commit 73658a5

Browse files
committed
added documentation for manual count
1 parent 2c3400c commit 73658a5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: Resources/doc/manual_counting.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Manual counting
2+
3+
**Note:** this documentation conserns more advanced usage of ORM
4+
query pagination. Paginator cannot support two **FROM** components
5+
or composite identifiers, because it cannot predict the total count
6+
in the database.
7+
8+
The solution to that is simple and direct, you can provide the **count**
9+
manually through the hint on the query.
10+
11+
## Usage example
12+
13+
``` php
14+
<?php
15+
16+
$paginator = new Paginator;
17+
18+
$count = $entityManager
19+
->createQuery('SELECT COUNT(c) FROM Entity\CompositeKey c')
20+
->getSingleScalarResult()
21+
;
22+
23+
$query = $entityManager
24+
->createQuery('SELECT c FROM Entity\CompositeKey c')
25+
->setHint('knp_paginator.count', $count)
26+
;
27+
$pagination = $paginator->paginate($query, 1, 10, array('distinct' => false));
28+
```
29+
30+
Distinction in this case also cannot be determined by paginator. It will take direct result
31+
of the query and limit with offset. In some cases you may need to use **GROUP BY**
32+

0 commit comments

Comments
 (0)