private function fixPersistentCollectionOwnership(PersistentCollectionInterface $coll, $document, ClassMetadata $class, $propName)
{
$owner = $coll->getOwner();
if ($owner === null) {
// cloned
$coll->setOwner($document, $class->fieldMappings[$propName]);
} elseif ($owner !== $document) {
// no clone, we have to fix
if (!$coll->isInitialized()) {
$coll->initialize();
// we have to do this otherwise the cols share state
}
$newValue = clone $coll;
$newValue->setOwner($document, $class->fieldMappings[$propName]);
$class->reflFields[$propName]->setValue($document, $newValue);
if ($this->isScheduledForUpdate($document)) {
// @todo following line should be superfluous once collections are stored in change sets
$this->setOriginalDocumentProperty(spl_object_hash($document), $propName, $newValue);
}
return $newValue;
}
return $coll;
}