Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1643

PersistentCollection should support clone

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 2.1.7, 2.2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      I'm trying to clone a PersistentCollection and expect to get a stable snapshot. But the class does not implement __clone, thus both objects refer to the same internal ArrayCollection.

      I can't use takeSnapshot because I'm writing generic code that should work with any implementation of Traversable/ArrayAccess.

        Activity

        Bernhard Schussek created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Project Doctrine Common [ 10043 ] Doctrine 2 - ORM [ 10032 ]
        Key DCOM-95 DDC-1643
        Affects Version/s 2.2 [ 10157 ]
        Affects Version/s 2.2 [ 10152 ]
        Security All [ 10000 ]
        Component/s ORM [ 10012 ]
        Component/s Collections [ 10052 ]
        Hide
        Benjamin Eberlei added a comment -

        Moved to right project

        Show
        Benjamin Eberlei added a comment - Moved to right project
        Hide
        Bernhard Schussek added a comment -

        Thank you for moving. Any comments on the feasibility of this issue?

        Show
        Bernhard Schussek added a comment - Thank you for moving. Any comments on the feasibility of this issue?
        Hide
        Benjamin Eberlei added a comment -

        I guess its feasible, i have to think about:

        1. how to fix the issue
        2. what behavior to attach in general.

        Show
        Benjamin Eberlei added a comment - I guess its feasible, i have to think about: 1. how to fix the issue 2. what behavior to attach in general.
        Hide
        Bernhard Schussek added a comment -

        Ok. For the sake of completeness, this issue directly causes another in Symfony2 which was already partially fixed here: https://github.com/symfony/symfony/pull/3315

        Show
        Bernhard Schussek added a comment - Ok. For the sake of completeness, this issue directly causes another in Symfony2 which was already partially fixed here: https://github.com/symfony/symfony/pull/3315
        Hide
        Josiah added a comment -
        Show
        Josiah added a comment - PR submitted for this issue: https://github.com/doctrine/doctrine2/pull/281
        Hide
        Benjamin Eberlei added a comment -

        What are you doing after the PersistentCollection is cloned?

        The reason is, that if the code looks like this:

        $col = clone $entity->getCol();
        $otherEntity->setCol($col);
        echo count($col);
        $em->flush();
        

        It will do very weird stuff using the owner of the association $col which is $entity. It will also try to insert the $col for $entity not for $otherEntity. To prevent this we have to do some work,

        Show
        Benjamin Eberlei added a comment - What are you doing after the PersistentCollection is cloned? The reason is, that if the code looks like this: $col = clone $entity->getCol(); $otherEntity->setCol($col); echo count($col); $em->flush(); It will do very weird stuff using the owner of the association $col which is $entity. It will also try to insert the $col for $entity not for $otherEntity. To prevent this we have to do some work,
        Hide
        Benjamin Eberlei added a comment -
        Show
        Benjamin Eberlei added a comment - Fixed in https://github.com/doctrine/doctrine2/commit/93f79d0810a158138020b4cca3332f9f0b1a76af and merged into 2.2 and 2.1.x
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.1.7 [ 10198 ]
        Fix Version/s 2.2.1 [ 10194 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13429 ] jira-feedback [ 15224 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15224 ] jira-feedback2 [ 17088 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17088 ] jira-feedback3 [ 19341 ]

        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-1643, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Bernhard Schussek
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: