Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1241

Additional parameters for EntityRepository::findAll() and EntityRepository::findOneBy()

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.3.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        Dmitry Pashkevich added a comment -

        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'));

        Show
        Dmitry Pashkevich added a comment - 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'));
        Show
        Fabio B. Silva added a comment - Fixed : https://github.com/doctrine/doctrine2/commit/283ed55824b7c713611e4b1e336551be805c48b5
        Hide
        Paweł Nowak added a comment -

        A proposed implementation of findOneBy with ordering is available with the following pull request: https://github.com/doctrine/doctrine2/pull/504.

        Show
        Paweł Nowak added a comment - A proposed implementation of findOneBy with ordering is available with the following pull request: https://github.com/doctrine/doctrine2/pull/504 .
        Hide
        Guilherme Blanco added a comment -

        Updating fix version

        Show
        Guilherme Blanco added a comment - Updating fix version
        Hide
        Benjamin Eberlei added a comment -

        Reopened for 2.2 with implementation for "findOneby()"

        Show
        Benjamin Eberlei added a comment - Reopened for 2.2 with implementation for "findOneby()"
        Hide
        Dieter Provoost added a comment -

        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.

        Show
        Dieter Provoost added a comment - 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.
        Hide
        Jasper N. Brouwer added a comment -

        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...

        Show
        Jasper N. Brouwer added a comment - 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...
        Hide
        Benjamin Eberlei added a comment -

        It was only added to "findBy"

        Show
        Benjamin Eberlei added a comment - It was only added to "findBy"
        Hide
        Dieter Provoost added a comment -

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

        Show
        Dieter Provoost added a comment - I can't seem to find the implementation of this even though this issue has been resolved. Is this possible?

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Jasper N. Brouwer
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: