diff --git a/src/Doctrine/DoctrineEventStore.php b/src/Doctrine/DoctrineEventStore.php index 4c51c89..ce36bdb 100644 --- a/src/Doctrine/DoctrineEventStore.php +++ b/src/Doctrine/DoctrineEventStore.php @@ -75,14 +75,14 @@ public function append(DomainEvent $domainEvent): void public function replace(DomainEvent $domainEvent): void { - $previous = $this->repository->findOneBy([ + $replaceableEvents = $this->repository->findBy([ 'aggregateRoot' => $domainEvent->getAggregateRootId(), 'typeName' => get_class($domainEvent), 'publishedOn' => null, ]); - if ($previous) { - $this->em->remove($previous); + foreach ($replaceableEvents as $replaceableEvent) { + $this->em->remove($replaceableEvent); } $this->append($domainEvent);