Skip to content

Recursively providing DataSubjectId for PersonalData in nested objects? #114

@wikando-ck

Description

@wikando-ck

Hi David & Daniel,
I'm using the package along with the event-sourcing bundle.

I stumbled upon the following case:

use Patchlevel\EventSourcing\Attribute\Event;
use Patchlevel\Hydrator\Attribute\DataSubjectId;
use Patchlevel\Hydrator\Attribute\PersonalData;

#[Event(name: 'some_event')]
final readonly class SomeEvent
{
    public function __construct(
        #[DataSubjectId]
        public int $id,
        public NestedData $data
    )
    {}
}

final readonly class NestedData
{
    public function __construct(
        public string $someFieldRequiredAfterCipherDestruction,
        #[PersonalData]
        public string $somePersonalData
    )
    {}
}

This would fail, as there is no DataSubjectId in the NestedData.
NestedData can be some immutable VO from my Domain, that I don't want to modify and it should not have an identifier.
So, to allow storing it, I'd need the hydrator to pass a DataSubjectId recursively into nested calls.
I've seen the work on named DataSubjectIds for 2.x, so this would not just be one DataSubjectId but a container that holds them.

I can also imagine that it'd be handy to have a way to tell the hydrator to use the aggregate id from the event surrounding the hydration as DataSubjectId.
Maybe as an attribute targeting classes: #[DataSubjectId(useAggregateId: true)]

I'd love to know your opinion about these.
Maybe there's something i'm not aware of to achieve this already?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions