title: Repository pattern for database and aggregate root
body: <p>I'm trying to understand the concept of 'aggregate root'.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Let's say I have a controller that uses a repository and queries a computer entity.</p>
  
  <pre><code>class Controller_Test {
  
      public function loadHardware($computerRepository)
      {
          $computer = $computerRepository-&gt;find_by_id(1);
          $hardware = $computer-&gt;hardware; // lazy load
      }
  }
  </code></pre>
  
  <p>If I'm using a database, I will end up executing two queries. One for the computer and another for the hardware.</p>
  
  <p>Wouldn't it make sense to have '<code>loadComputerWithHardware</code>' 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)?</p>