Skip to content

Commit

Permalink
Use UnitOfWork::registerManaged instead of updating ::$identityMap di…
Browse files Browse the repository at this point in the history
…rectly

This way, only one place in the code writes to ::$identityMap 👍
  • Loading branch information
mpdude committed Jun 23, 2023
1 parent aa3dd24 commit c453b74
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 65 deletions.
15 changes: 5 additions & 10 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -2796,25 +2796,20 @@ public function createEntity($className, array $data, &$hints = [])
}

$this->originalEntityData[$oid] = $data;

if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
} else {
$entity = $this->newInstance($class);
$oid = spl_object_id($entity);

$this->entityIdentifiers[$oid] = $id;
$this->entityStates[$oid] = self::STATE_MANAGED;
$this->originalEntityData[$oid] = $data;

$this->identityMap[$class->rootEntityName][$idHash] = $entity;
$this->registerManaged($entity, $id, $data);

if (isset($hints[Query::HINT_READ_ONLY])) {
$this->readOnlyObjects[$oid] = true;
}
}

if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}

foreach ($data as $field => $value) {
if (isset($class->fieldMappings[$field])) {
$class->reflFields[$field]->setValue($entity, $value);
Expand Down
54 changes: 0 additions & 54 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2785Test.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getClassMetadata($className): ClassMetadata
$uow->clear();
$uow->triggerEagerLoads();

self::assertSame(3, $em->getClassMetadataCalls);
self::assertSame(4, $em->getClassMetadataCalls);
}
}

Expand Down

0 comments on commit c453b74

Please sign in to comment.