laravel-event-sourcing icon indicating copy to clipboard operation
laravel-event-sourcing copied to clipboard

Aggregate Partial is ignored when creating a snapshot

Open saschanowak opened this issue 3 years ago • 3 comments

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.

saschanowak avatar Jan 08 '22 17:01 saschanowak

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.

  1. Is your partial aggregate root Public property of your aggregate?
  2. 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.

image

etahamer avatar Jan 08 '22 17:01 etahamer

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: image

saschanowak avatar Jan 08 '22 21:01 saschanowak

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.

brendt avatar Jan 10 '22 04:01 brendt

This should now be closed as it has been fixed in PR #406

sonja-turo avatar Oct 03 '23 01:10 sonja-turo