laravel-event-sourcing
laravel-event-sourcing copied to clipboard
Aggregate Partial is ignored when creating a snapshot
I'm playing around with this package and noticed, that when following the documentation for aggregate partials and creating a snapshot of the aggregate root, the state of the partial is not stored in the snapshot. Not sure if that is intended or a bug, as I didn't find a test for this usecase and the documentation didn't mentions snapshots and aggregate partials.
Hello
@nlx-sascha
I'm playing around with this package and noticed, that when following the documentation for aggregate partials and creating a snapshot of the aggregate root, the state of the partial is not stored in the snapshot. Not sure if that is intended or a bug, as I didn't find a test for this usecase and the documentation didn't mentions snapshots and aggregate partials.
- Is your partial aggregate root Public property of your aggregate?
- Are the properties that you expect to snapshot public in aggregate partial?
It would be great if you shown us what your code looks like and also what is saved in snapshots table
If you looked into: \Spatie\EventSourcing\AggregateRoots\AggregateRoot::getState you will see that properties must be public to be snapshoted.
Hey @etahamer,
thanks for the quick response.
Without trying it deeper I think making the AggregatePartial public does not feel right. Correct me if I'm wrong, but the interaction with the AggregatePartial should not be possible from outside. Thats when you need to proxy all functions from the AggregateRoot to the AggregatePartial like in the documentation example.
Also when reading the code the useState
function only handles scalar values and does not convert the values of the aggregate partial to the correct object:
Partials should indeed not be made public. I'd say this issue is mostly an oversight, though I'm not sure whether it can be easily fixed. I welcome a PR that addresses the issue.
This should now be closed as it has been fixed in PR #406