Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1927

Pagination of a SELECT of specific fields results in a RuntimeException

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Can't Fix
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:

      Description

      When paginating a DQL string which selects specific fields it results in the following error: PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Not all identifier properties can be found in the ResultSetMapping: id'

      NOT working: 'SELECT c.id, c.number FROM Application\Entity\Course c'
      WORKING: 'SELECT c FROM Application\Entity\Course c'
      WORKING: 'SELECT c, c.id, c.number FROM Application\Entity\Course c'

      Setting hydration mode to scalar results makes no difference.

      Gist to example code and stack trace: https://gist.github.com/d5cd6d0b0ac28e722dd7

        Activity

        Hide
        Busta Rhymes added a comment -

        Did i miss something about Doctrine 2 ? What is the point if we can't use pagination? Selecting only several/needed fields is as standard practice as brushing your teeth every day. And pagination doesn't work when i select only specific fields (it throws 'Not all identifier properties can be found in the ResultSetMapping: id' error). I also thought that `$query->setFirstResult(20);` and `$query->setMaxResults(100);` works fine with joins but it turns out it doesn't work. It looks too complicated to integrate such common tool as pagination (I'm switching from CakePHP based ORM which works just fine with any kind of joins etc, no problems with pagination so far, but we are switching to Symfony 2 which goes with Doctrine 2 and actually i was recommended to use Doctrine 2, but i clearly see solid problems atm :/)

        Show
        Busta Rhymes added a comment - Did i miss something about Doctrine 2 ? What is the point if we can't use pagination? Selecting only several/needed fields is as standard practice as brushing your teeth every day. And pagination doesn't work when i select only specific fields (it throws 'Not all identifier properties can be found in the ResultSetMapping: id' error). I also thought that `$query->setFirstResult(20);` and `$query->setMaxResults(100);` works fine with joins but it turns out it doesn't work. It looks too complicated to integrate such common tool as pagination (I'm switching from CakePHP based ORM which works just fine with any kind of joins etc, no problems with pagination so far, but we are switching to Symfony 2 which goes with Doctrine 2 and actually i was recommended to use Doctrine 2, but i clearly see solid problems atm :/)
        Hide
        Zacharias Luiten added a comment -

        @Busta Rhymes - Use partial entities (only the data of the fields you specify is fetched and set in the entity). As pagination is most of the time used just for displaying data, one is fine with that.

        Show
        Zacharias Luiten added a comment - @Busta Rhymes - Use partial entities (only the data of the fields you specify is fetched and set in the entity). As pagination is most of the time used just for displaying data, one is fine with that.
        Hide
        Thomas Godar added a comment -

        I was pretty disappointed with this resolution. I fail to see how the tasks of a paginator fail to work with Query object foo yet work with Query object bar. They are the same objects. I would think a query is a query for the intent and purpose of the paginator, get a count, set limit and offset, give me back the page of results. All the more so if that Query has HydrationMode set to an array.

        What does "generic+complex pagination" even mean?

        Show
        Thomas Godar added a comment - I was pretty disappointed with this resolution. I fail to see how the tasks of a paginator fail to work with Query object foo yet work with Query object bar. They are the same objects. I would think a query is a query for the intent and purpose of the paginator, get a count, set limit and offset, give me back the page of results. All the more so if that Query has HydrationMode set to an array. What does "generic+complex pagination" even mean?
        Hide
        Marco Pivetta added a comment -

        As discussed in private, the problem is that doctrine needs a selected root entity in a DQL query in order to paginate the results.

        That's a current limitation that cannot be worked around.

        What could be done is giving a "meaning" to scalars being selected, so that they are upgraded to (for example) identifiers of a particular root entity.

        That is still not worth it given the amount of bugs and increase in LOC that spawns from it.

        Show
        Marco Pivetta added a comment - As discussed in private, the problem is that doctrine needs a selected root entity in a DQL query in order to paginate the results. That's a current limitation that cannot be worked around. What could be done is giving a "meaning" to scalars being selected, so that they are upgraded to (for example) identifiers of a particular root entity. That is still not worth it given the amount of bugs and increase in LOC that spawns from it.
        Hide
        Steve Todorov added a comment -

        For anybody who might be experiencing this issue, a possible workaround might be:

        $paginator = new Paginator($query);
        $paginator->setUseOutputWalkers(false);

        Show
        Steve Todorov added a comment - For anybody who might be experiencing this issue, a possible workaround might be: $paginator = new Paginator($query); $paginator->setUseOutputWalkers(false);

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Zacharias Luiten
          • Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: