DDC-1241: Additional parameters for EntityRepository::findAll() and EntityRepository::findOneBy() #1850

Closed
doctrinebot opened this Issue Jul 1, 2011 · 10 comments

2 participants

@doctrinebot

Jira issue originally created by user jasper@nerdsweide.nl:

In the Doctrine 2.1 versions the method EntityRepository::findBy() accepts additional parameters for ordering, limit and offset.
Great feature! (While waiting for it I extended the EntityRepository class and implemented these parameters myself using a QueryBuilder.)

It would be nice for the method EntityRepository::findOneBy() to accept an additional parameter for ordering as well. It could use the following signature:
public function findOneBy(array $criteria, array $orderBy = null);
This would be useful for various cases, for example: finding the newest blog-post.

And maybe update EntityRepository::findAll() as well with the signature:
public function findAll(array $orderBy = null);

Looking forward to your thoughts.

@doctrinebot

Comment created by dieterprovoost:

I can't seem to find the implementation of this even though this issue has been resolved. Is this possible?

@doctrinebot

Comment created by @beberlei:

It was only added to "findBy"

@doctrinebot

Comment created by jasper@nerdsweide.nl:

So the resolution is actually a "won't fix" (in stead of "fixed")?

I know this was added to "findBy", but my request was to extend the "findOneBy" and "findAll" as well...

@doctrinebot

Comment created by dieterprovoost:

Can it also be added to "findOneBy"? It would come in very handy for the use case above (for example: finding the newest blog-post).
Otherwise, I think we are limited to the alternative using "findBy" with the orderBy parameter (thus fetching all entries, followed by returning only the first/last) or using a native query.

@doctrinebot

Comment created by @beberlei:

Reopened for 2.2 with implementation for "findOneby()"

@doctrinebot

Comment created by @guilhermeblanco:

Updating fix version

@doctrinebot

Comment created by nemek_zg:

A proposed implementation of findOneBy with ordering is available with the following pull request: #504.

@doctrinebot

Comment created by @FabioBatSilva:

Fixed : 283ed55

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by dpashkevich:

What about extending the signature of EntityRepository::findAll() to this?
public function findAll(array $orderBy = null);

I like this idea, it would allow cleaner code when querying records without criteria:
$users->findAll(array('name'=>'ASC'));
instead of
$users->findBy(array(), array('name'=>'ASC'));

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.3.1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment