Skip to content

Commit 5378284

Browse files
authored
Merge pull request #438 from joelwurtz/patch-1
Add doc on pagination_fetch_join_collection
2 parents 6236b55 + 9a03c8a commit 5378284

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

core/pagination.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,29 @@ class Book
319319
// ...
320320
}
321321
```
322+
323+
## Avoiding double SQL requests on Doctrine
324+
325+
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 imply that 2 sql requests will be executed (so this avoid having less results than expected).
326+
327+
In most cases, even without collection on the resource, this parameter has little impact on performance. However when fetching a lot of results per page it can be counter productive.
328+
329+
That's why this behavior can be configured with the `pagination_fetch_join_collection` parameter on a resource:
330+
331+
```php
332+
<?php
333+
334+
// src/Entity/Book.php
335+
336+
use ApiPlatform\Core\Annotation\ApiResource;
337+
338+
/**
339+
* @ApiResource(attributes={"pagination_fetch_join_collection"=false})
340+
*/
341+
class Book
342+
{
343+
// ...
344+
}
345+
```
346+
347+
Please note that this parameter will always be forced to false when the resource have composite keys due to a [bug in doctrine](https://github.com/doctrine/doctrine2/issues/2910)

0 commit comments

Comments
 (0)