You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/pagination.md
+38-6Lines changed: 38 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -320,6 +320,38 @@ class Book
320
320
}
321
321
```
322
322
323
+
## Cursor based pagination
324
+
325
+
To configure your resource to use the cursor-based pagination, select your unique sorted field as well as the direction you’ll like the pagination to go via filters and enable the `pagination_via_cursor` option.
326
+
327
+
### For a Specific Resource
328
+
329
+
```php
330
+
<?php
331
+
332
+
// api/src/Entity/Book.php
333
+
334
+
use ApiPlatform\Core\Annotation\ApiFilter;
335
+
use ApiPlatform\Core\Annotation\ApiResource;
336
+
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\OrderFilter;
337
+
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\RangeFilter;
To know more about cursor-based pagination take a look at [this blog post on medium](https://medium.com/@sroze/74fd1d324723).
354
+
323
355
## Avoiding double SQL requests on Doctrine ORM
324
356
325
357
By default, pagination assumes that there will be collection fetched on a resource and thus will set `useFetchJoinCollection` to `true` on the Doctrine Paginator class. Having this option implies that 2 SQL requests will be executed (so this avoid having less results than expected).
@@ -371,21 +403,21 @@ use Doctrine\Common\Collections\Criteria;
371
403
class BookRepository extends ServiceEntityRepository
372
404
{
373
405
const ITEMS_PER_PAGE = 20;
374
-
406
+
375
407
private $tokenStorage;
376
-
408
+
377
409
public function __construct(
378
410
RegistryInterface $registry,
379
411
TokenStorageInterface $tokenStorage
380
412
) {
381
413
$this->tokenStorage = $tokenStorage;
382
414
parent::__construct($registry, Book::class);
383
415
}
384
-
416
+
385
417
public function getBooksByFavoriteAuthor(int $page = 1): Paginator
0 commit comments