I'm trying to understand the concept of 'aggregate root'.
One of the things that confuses me is that I should not access a child entity directly without accessing its aggregate root. For example, let's say I have a computer entity and a hardware entity.
As far as I understand, I should not directly access a hardware entity directly. I should access a hardware entity through its aggregate root, which is a computer entity.
Let's say I have a controller that uses a repository and queries a computer entity.
class Controller_Test {
public function loadHardware($computerRepository)
{
$computer = $computerRepository->find_by_id(1);
$hardware = $computer->hardware; // lazy load
}
}
If I'm using a database, I will end up executing two queries. One for the computer and another for the hardware.
Wouldn't it make sense to have 'loadComputerWithHardware
' in my repository to save # of queries? Does it violate a rule of DDD (by querying a computer and hardware together by joining two tables)?