Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      Hello,

      I'm sorry if it is not the right place to ask and suggest but I was not sure where to contact you.

      I have been trying to make a pagination of articles without using DQL. For me, it defies the purpose of the ORM to do DQL for things like pagination.

      After some research I found the method findBy() which allows me to select X element starting at position Y.
      Yet, to know the number of pages, I needed to count the number of elements in my database and I didn't find any count() method in the Entity Repository.

      I was wondering why there is no count method ?

      Moreover, I did my own entity Repository that extends the default one to have a count method like this :

      use Doctrine\ORM\EntityRepository;
      
      class CountableEntityRepository extends EntityRepository {
          
          /**
           * returns the number of entity's rows
           * @return int
           */
          public function count() {
              $query = $this->createQueryBuilder('e')->select('count(e)')->getQuery();
              return $query->getSingleScalarResult();
          }
      }

      as I am new to Doctrine I don't know if this is a good solution, if it is not, could you add a count method to the repository ?

      Thank you very much.

      Regards,
      Benjamin.

        Activity

        Benjamin created issue -
        Marco Pivetta made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        Resolution Invalid [ 6 ]

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Benjamin
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: