Skip to content

Commit

Permalink
README.md - Explain how to paginate
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixelshaped committed Jun 5, 2024
1 parent 2859de5 commit b21ec89
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ $flatMapper->map(CustomerDTO::class, $result);

Will give you an array of `CustomerDTO`, with the `$shoppingListIds` property populated with an array of corresponding ShoppingList IDs.

### Working with pagination

You can still use [Doctrine](https://www.doctrine-project.org/projects/doctrine-orm/en/3.2/tutorials/pagination.html) to paginate your DQL query:

```php
$qb = $customerRepository->createQueryBuilder('customer');
$qb
->leftJoin('customer.addresses', 'customer_addresses')
->select('customer.id AS customer_id, customer.ref AS customer_ref, customer_addresses.id AS address_id')
->setFirstResult(0)
->setMaxResults(10)
;

$paginator = new Paginator($qb->getQuery(), fetchJoinCollection: true);
$paginator->setUseOutputWalkers(false);

$result = $flatMapper->map(CustomerWithAddressesDTO::class, $paginator);
```

Will get you an array of 10 `CustomerWithAddressesDTO` (granted you do have 10 in your db).

### Usage without Symfony

You can use this package without Symfony. Just instantiate the `FlatMapper` class and use its methods.
Expand Down

0 comments on commit b21ec89

Please sign in to comment.