-
-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix root document entityMap #2726
base: 2.10.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1505,11 +1505,11 @@ public function addToIdentityMap(object $document): bool | |
$class = $this->dm->getClassMetadata($document::class); | ||
$id = $this->getIdForIdentityMap($document); | ||
|
||
if (isset($this->identityMap[$class->name][$id])) { | ||
if (isset($this->identityMap[$class->rootDocumentName][$id])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This need to be addressed and covered by tests: #2725 (comment)
We can update the value of @malarzm any idea? I don't understand the purpose of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I was using COLLECTION_PER_CLASS years ago to work around some mapped superclass limitations, but it's been so long I can't be sure. |
||
return false; | ||
} | ||
|
||
$this->identityMap[$class->name][$id] = $document; | ||
$this->identityMap[$class->rootDocumentName][$id] = $document; | ||
|
||
if ($document instanceof NotifyPropertyChanged && ! $this->isUninitializedObject($document)) { | ||
$document->addPropertyChangedListener($this); | ||
|
@@ -1597,8 +1597,8 @@ public function removeFromIdentityMap(object $document): bool | |
$class = $this->dm->getClassMetadata($document::class); | ||
$id = $this->getIdForIdentityMap($document); | ||
|
||
if (isset($this->identityMap[$class->name][$id])) { | ||
unset($this->identityMap[$class->name][$id]); | ||
if (isset($this->identityMap[$class->rootDocumentName][$id])) { | ||
unset($this->identityMap[$class->rootDocumentName][$id]); | ||
$this->documentStates[$oid] = self::STATE_DETACHED; | ||
|
||
return true; | ||
|
@@ -1629,7 +1629,7 @@ public function getById($id, ClassMetadata $class): object | |
|
||
$serializedId = serialize($class->getDatabaseIdentifierValue($id)); | ||
|
||
return $this->identityMap[$class->name][$serializedId]; | ||
return $this->identityMap[$class->rootDocumentName][$serializedId]; | ||
} | ||
|
||
/** | ||
|
@@ -1658,7 +1658,7 @@ public function tryGetById($id, ClassMetadata $class) | |
|
||
$serializedId = serialize($class->getDatabaseIdentifierValue($id)); | ||
|
||
return $this->identityMap[$class->name][$serializedId] ?? false; | ||
return $this->identityMap[$class->rootDocumentName][$serializedId] ?? false; | ||
} | ||
|
||
/** | ||
|
@@ -1688,7 +1688,7 @@ public function isInIdentityMap(object $document): bool | |
$class = $this->dm->getClassMetadata($document::class); | ||
$id = $this->getIdForIdentityMap($document); | ||
|
||
return isset($this->identityMap[$class->name][$id]); | ||
return isset($this->identityMap[$class->rootDocumentName][$id]); | ||
} | ||
|
||
private function getIdForIdentityMap(object $document): string | ||
|
@@ -2768,13 +2768,13 @@ public function getOrCreateDocument(string $className, array $data, array &$hint | |
if (! $class->isQueryResultDocument) { | ||
$id = $class->getDatabaseIdentifierValue($data['_id']); | ||
$serializedId = serialize($id); | ||
$isManagedObject = isset($this->identityMap[$class->name][$serializedId]); | ||
$isManagedObject = isset($this->identityMap[$class->rootDocumentName][$serializedId]); | ||
} | ||
|
||
$oid = null; | ||
if ($isManagedObject) { | ||
/** @phpstan-var T $document */ | ||
$document = $this->identityMap[$class->name][$serializedId]; | ||
$document = $this->identityMap[$class->rootDocumentName][$serializedId]; | ||
$oid = spl_object_hash($document); | ||
if ($this->isUninitializedObject($document)) { | ||
$document->setProxyInitializer(null); | ||
|
@@ -2798,9 +2798,9 @@ public function getOrCreateDocument(string $className, array $data, array &$hint | |
|
||
if (! $class->isQueryResultDocument) { | ||
$this->registerManaged($document, $id, $data); | ||
$oid = spl_object_hash($document); | ||
$this->documentStates[$oid] = self::STATE_MANAGED; | ||
$this->identityMap[$class->name][$serializedId] = $document; | ||
$oid = spl_object_hash($document); | ||
$this->documentStates[$oid] = self::STATE_MANAGED; | ||
$this->identityMap[$class->rootDocumentName][$serializedId] = $document; | ||
} | ||
|
||
$data = $this->hydratorFactory->hydrate($document, $data, $hints); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to add this condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the response here: #2725 (comment)