You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Next I created a MentionsAggregatePartial to keep things separated because I might use it on some other content column
classMentionsAggregatePartialextendsAggregatePartial
{
protectedarray$mentionedUsersId = [];
publicfunctiononMentionsAdded(EntryContentUpdated$event)
{
// When user is tagged in content for the first time$this->recordThat(newUserMentioned($userId));
}
}
Also, to be able to add partials from packages I overrode the method resolvePartials like so:
Everything seemed to work perfectly! But only the first time, the second update triggered the exception: Could not persist aggregate EntryAggregateRoot .... because it seems to be changed by another process after it was retrieved in the current process. Expect to persist events after version 21, but version 20 was already persisted.
So I inspected the source code and I come up this change that fixed the problem:
abstractclassAggregateRoot
{
// ...publicfunctionrecordThat(ShouldBeStored$domainEvent): static
{
$domainEvent
->setAggregateRootUuid($this->uuid)
->setCreatedAt(CarbonImmutable::now());
$this->recordedEvents[] = $domainEvent;
$this->apply($domainEvent);
$domainEvent->setAggregateRootVersion($this->aggregateVersion);
// Moved here the apply on the aggregate partials outside the main apply and // after the set for the aggregate root version aboveforeach ($this->resolvePartials() as$partial) {
$partial->apply($domainEvent);
}
return$this;
}
// ...
}
Now everything works but I am not sure if this has some consequences. Also, I cannot really do that change without reflection magic because some property on the abstract class are private.
I'll wait some comments/feedbacks, thanks!
The text was updated successfully, but these errors were encountered:
Hello, to give some context the scenario I was in is: trying to send a notification when a user is tagged in some content.
I created the
EntryAggregateRoot
which has a method to update the contentupdateEntryContent(string $content)
.Next I created a
MentionsAggregatePartial
to keep things separated because I might use it on some other content columnAlso, to be able to add partials from packages I overrode the method
resolvePartials
like so:Everything seemed to work perfectly! But only the first time, the second update triggered the exception:
Could not persist aggregate EntryAggregateRoot .... because it seems to be changed by another process after it was retrieved in the current process. Expect to persist events after version 21, but version 20 was already persisted.
So I inspected the source code and I come up this change that fixed the problem:
Now everything works but I am not sure if this has some consequences. Also, I cannot really do that change without reflection magic because some property on the abstract class are private.
I'll wait some comments/feedbacks, thanks!
The text was updated successfully, but these errors were encountered: