Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2213

Paginator does not work with composite primary key entity

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3.1
    • Fix Version/s: None
    • Component/s: ORM, Tools
    • Security Level: All
    • Environment:
      php 5.4

      Description

      Paginator does not work with composed primary key.

      "Single id is not allowed on composite primary key in entity" exception is thrown here
      https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php#L90

      Only first column values are fetched while retrieving primary keys here
      https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/Paginator.php#L173

        Activity

        Stanislav Anisimov created issue -
        Stanislav Anisimov made changes -
        Field Original Value New Value
        Description Paginator does not work with composed primary key, because only first column values are fetched while retrieving primary keys here
        https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/Paginator.php#L173
        Paginator does not work with composed primary key.

        "Single id is not allowed on composite primary key in entity" exception is thrown here
        https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php#L90

        Only first column values are fetched while retrieving primary keys here
        https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/Paginator.php#L173
        Hide
        Marco Pivetta added a comment -

        Limitation was confused by issue reporter and considered bug

        Show
        Marco Pivetta added a comment - Limitation was confused by issue reporter and considered bug
        Marco Pivetta made changes -
        Issue Type Bug [ 1 ] New Feature [ 2 ]
        Priority Critical [ 2 ] Major [ 3 ]
        Austin Morris made changes -
        Description Paginator does not work with composed primary key.

        "Single id is not allowed on composite primary key in entity" exception is thrown here
        https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php#L90

        Only first column values are fetched while retrieving primary keys here
        https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/Paginator.php#L173
        Paginator does not work with composed primary key.

        "Single id is not allowed on composite primary key in entity" exception is thrown here
        https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php#L90

        Only first column values are fetched while retrieving primary keys here
        https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/Paginator.php#L173
        Hide
        Austin Morris added a comment -

        I'd like to add some additional information because the title and description are misleading.

        Paginator does work with composite primary key entities. You just cannot use the Paginator when your query does a fetch join with a collection (a one-to-many or many-to-many association). See the documentation for a brief description:
        http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/pagination.html

        In order to use Paginator with a composite primary key entity, you need to instantiate the Paginator with the $fetchJoinCollection flag set to false (it defaults to true). Now, pagination will skip the WhereInWalker which throws an exception when using a composite primary key. Fetch joins with entities (one-to-one or many-to-one) will still work. You can even use a regular join with a collection.

        The only "problem" is when your Paginator query calls for a fetch join to a collection. The work around for this is to use a regular join as mentioned above. The drawback is that your paginated entities will not be hydrated with the collection. The collection will have to be lazy-loaded when called upon.

        Show
        Austin Morris added a comment - I'd like to add some additional information because the title and description are misleading. Paginator does work with composite primary key entities. You just cannot use the Paginator when your query does a fetch join with a collection (a one-to-many or many-to-many association). See the documentation for a brief description: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/pagination.html In order to use Paginator with a composite primary key entity, you need to instantiate the Paginator with the $fetchJoinCollection flag set to false (it defaults to true). Now, pagination will skip the WhereInWalker which throws an exception when using a composite primary key. Fetch joins with entities (one-to-one or many-to-one) will still work. You can even use a regular join with a collection. The only "problem" is when your Paginator query calls for a fetch join to a collection. The work around for this is to use a regular join as mentioned above. The drawback is that your paginated entities will not be hydrated with the collection. The collection will have to be lazy-loaded when called upon.

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2213, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Stanislav Anisimov
          • Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

            • Created:
              Updated: