Skip to content

Commit

Permalink
doctrine#6759 avoiding reuse of the $identifier variable when const…
Browse files Browse the repository at this point in the history
…ructing an identifier from the owning side value

Fixes doctrine#6759
  • Loading branch information
Ocramius authored and maglnet committed Oct 10, 2018
1 parent 6815adf commit ae00757
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifie
$sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']);
$owningAssoc = $targetClass->getAssociationMapping($assoc['mappedBy']);

$computedIdentifier = [];

// TRICKY: since the association is specular source and target are flipped
foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) {
if ( ! isset($sourceClass->fieldNames[$sourceKeyColumn])) {
Expand All @@ -802,13 +804,11 @@ public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifie

// unset the old value and set the new sql aliased value here. By definition
// unset($identifier[$targetKeyColumn] works here with how UnitOfWork::createEntity() calls this method.
$identifier[$targetClass->getFieldForColumn($targetKeyColumn)] =
$computedIdentifier[$targetClass->getFieldForColumn($targetKeyColumn)] =
$sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);

unset($identifier[$targetKeyColumn]);
}

$targetEntity = $this->load($identifier, null, $assoc);
$targetEntity = $this->load($computedIdentifier, null, $assoc);

if ($targetEntity !== null) {
$targetClass->setFieldValue($targetEntity, $assoc['mappedBy'], $sourceEntity);
Expand Down

0 comments on commit ae00757

Please sign in to comment.