Skip to content

Loading…

DDC-1643: PersistentCollection should support clone #2285

Closed
doctrinebot opened this Issue · 8 comments

2 participants

@doctrinebot

Jira issue originally created by user bschussek:

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.

@doctrinebot

Comment created by @beberlei:

Moved to right project

@doctrinebot

Comment created by bschussek:

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

@doctrinebot

Comment created by @beberlei:

I guess its feasible, i have to think about:

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

Comment created by bschussek:

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

@doctrinebot

Comment created by auswebdev:

PR submitted for this issue: #281

@doctrinebot

Comment created by @beberlei:

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,

@doctrinebot

Comment created by @beberlei:

Fixed in 93f79d0 and merged into 2.2 and 2.1.x

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.1.7 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.