In DDD, the repository takes on the task of storing and retrieving domain objects, and also serves to collect aggregate roots. My question is, how do you retrieve information for these child objects (say, from the database) from the Aggregate, where the Repository is the main rule, should just store the Aggregate Roots collection (the parent object) and not the child objects?
For instance:
User (parent) Orders (child)
The user domain object is stored in the user table, and Orders are stored in another table.
Basically, getting a domain object can be like this:
<?php
$userRepos = new UserRepository();
$user = $userRepos->find($userId);
?>
How then to get the child object (Orders) of the user object as part of the user aggregate?
source
share