How to retrieve Aggregate objects?
- by Jebb
In DDD, Repository takes care of saving and retrieving domain objects and also serves as collection of Aggregate Roots. My question is how do you retrieve the information for those child entities (let's say from DB) of an Aggregate where basic rule is Repository should just hold collection of Aggregate Roots (parent object) and not child objects?
For example:
User (parent object)
Orders (child object)
User domain object is stored in user table and Orders are stored in another table.
Basically, retrieving a Domain Object could be like this:
<?php
$userRepos = new UserRepository();
$user = $userRepos->find($userId);
?>
How then the child object (Orders) of User entity be retrieve to be as part of the User aggregate?