whiteoctober / Pagerfanta

Pagination for PHP.
Other
1.59k stars 2 forks source link

how to add a custom hydrationMode #247

Closed plesiosaure closed 6 years ago

plesiosaure commented 6 years ago

It seems that you can set HydrationMode with magical method setHydrationMode on the query before sending to Paginator (see issue #102) but not use a custom one : without pagination, you just need to pass the hydrator as a parameter of getResult()

So how to add a new field that is not provided in the raw entities datas returned by the query ?

stof commented 6 years ago

So passing the hydration mode to getResult allows passing a custom one in the ORM but setHydrationModedoes not ? This looks weird to me.

plesiosaure commented 6 years ago

sorry, it works with passing the key defined in the config.yml :

setHydrationMode('my_custom_hydrator')

but not if you use the entity manager as described in the doctrine doc :

$em->getConfiguration()->addCustomHydrationMode('CustomHydrator', 'MyProject\Hydrators\CustomHydrator'); 
//this seems to work if you dump entity manager : it is added
 setHydrationMode('CustomHydrator'); // didn'twork for me