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
+39-6Lines changed: 39 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -320,6 +320,39 @@ 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
+
Note that for now you have to declare a `RangeFilter` and an `OrderFilter` on the property used for the cursor-based pagination.
327
+
328
+
The following configuration also works on a specific operation:
329
+
330
+
```php
331
+
<?php
332
+
333
+
// api/src/Entity/Book.php
334
+
335
+
use ApiPlatform\Core\Annotation\ApiFilter;
336
+
use ApiPlatform\Core\Annotation\ApiResource;
337
+
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\OrderFilter;
338
+
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).
355
+
323
356
## Avoiding double SQL requests on Doctrine ORM
324
357
325
358
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 +404,21 @@ use Doctrine\Common\Collections\Criteria;
371
404
class BookRepository extends ServiceEntityRepository
372
405
{
373
406
const ITEMS_PER_PAGE = 20;
374
-
407
+
375
408
private $tokenStorage;
376
-
409
+
377
410
public function __construct(
378
411
RegistryInterface $registry,
379
412
TokenStorageInterface $tokenStorage
380
413
) {
381
414
$this->tokenStorage = $tokenStorage;
382
415
parent::__construct($registry, Book::class);
383
416
}
384
-
417
+
385
418
public function getBooksByFavoriteAuthor(int $page = 1): Paginator
0 commit comments