persistence icon indicating copy to clipboard operation
persistence copied to clipboard

RFC: Add optional orderBy parameter to findAll

Open maldoinc opened this issue 6 years ago • 3 comments

In this patch I want to discuss the possibility of adding an optional parameter to the findAll method, that IMO makes sense to be there: $orderBy.

When one needs to fetch the data sorted differently than the default method findAll is of no use and one has to use findBy([], $orderBy), which makes it slightly less readable as there are no filters being applied, but rather it is used only for sorting. Said calls then can be changed to findAll($orderBy)

If the maintainers agree that this is a positive change then I can also send the corresponding PR for doctrine/orm and any documentation changes.

maldoinc avatar Aug 17 '19 08:08 maldoinc

If we make changes to the signature of findAll, I would vote for using the same signature we use for the findBy method, minus the $criteria argument:

public function findAll(array $orderBy = [], $limit = null, $offset = null)

Opinions @doctrine/doctrinecore?

alcaeus avatar Aug 17 '19 08:08 alcaeus

My reasoning for not adding limit and offset is because then it's not technically "all" anymore.

maldoinc avatar Aug 17 '19 09:08 maldoinc

My reasoning for not adding limit and offset is because then it's not technically "all" anymore.

🤦‍♂️ Um, yeah. That makes sense.

alcaeus avatar Aug 17 '19 10:08 alcaeus