I'm trying use DDD in an application I'm currently working on. I have a following UserAggregate structure:
UserAggregate
- ProfileEntity
- ImageEntity
- RatingEntity
And i have a UserRepository which is querying entities mappers to build a UserAggregate.
Now I'd like to pass the UserAggregate to the UserRepository for persistance, like UserRepository->save(UserAggregate)
. How do I tell the UserRepository that UserAggregate children entities have changed and needs to be saved? Is there any common pattern for that? I'm aware of UintOfWork pattern but can't really imagine how it may help with children, as I'd like to hit the mappers (and the database) only if the children entities are actually changed.
Is there any way to track a "dirty state" of the entity object, specifically in PHP? Or Am I missed the concept of aggregate roots and repositories?