Skip to content

Commit e9356d2

Browse files
committed
remove also removes from identitymap
1 parent 6c00cda commit e9356d2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/Model/IdentityMap.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ public function get(
5858
}
5959

6060

61+
public function remove(
62+
\Spameri\Elastic\Entity\AbstractElasticEntity $entity,
63+
): void
64+
{
65+
if ($entity->id instanceof \Spameri\Elastic\Entity\Property\EmptyElasticId) {
66+
return;
67+
}
68+
69+
unset($this->identityMap[$entity::class][$entity->id()->value()]);
70+
unset($this->persisted[$entity::class][$entity->id()->value()]);
71+
72+
/** @var string|false $parentClass */
73+
$parentClass = \get_parent_class($entity);
74+
if (
75+
\is_string($parentClass) === true
76+
&& $parentClass !== \Spameri\Elastic\Entity\AbstractElasticEntity::class
77+
) {
78+
unset($this->identityMap[$parentClass][$entity->id()->value()]);
79+
}
80+
}
81+
82+
6183
public function markInserted(
6284
\Spameri\Elastic\Entity\AbstractElasticEntity $entity,
6385
): void

0 commit comments

Comments
 (0)