Doctrine\ODM\MongoDB\UnitOfWork::fixPersistentCollectionOwnership PHP 메소드

fixPersistentCollectionOwnership() 개인적인 메소드

Fixes PersistentCollection state if it wasn't used exactly as we had in mind: 1) sets owner if it was cloned 2) clones collection, sets owner, updates document's property and, if necessary, updates originalData 3) NOP if state is OK Returned collection should be used from now on (only important with 2nd point)
private fixPersistentCollectionOwnership ( Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface $coll, object $document, ClassMetadata $class, string $propName ) : Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface
$coll Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface
$document object
$class Doctrine\ODM\MongoDB\Mapping\ClassMetadata
$propName string
리턴 Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface
    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;
    }
UnitOfWork