title: CakePHP Multiple Nested Joins
body: <p>I have an App in which several of the models are linked by hasMany/belongsTo associations.  So for instance, A hasMany B, B hasMany C, C hasMany D, and D hasMany E.  Also, E belongs to D, D belongs to C, C belongs to B, and B belongs to A.  Using the Containable behavior has been great for controlling the amount of information comes back with each query, but I seem to be having a problem when trying to get data from table A while using a condition that involves table D.  For instance, here is an example of my 'A' model:</p>
  
  <pre><code>class A extends AppModel {
      var $name = 'A';
  
      var $hasMany = array(
          'B' =&gt; array('dependent' =&gt; true)
      );
  
      function findDependentOnE($condition) {
          return $this-&gt;find('all', array(
              'contain' =&gt; array(
                  'B' =&gt; array(
                      'C' =&gt; array(
                          'D' =&gt; array(
                              'E' =&gt; array(
                                  'conditions' =&gt; array(
                                      'E.myfield' =&gt; $some_value
                                  )
                              )
                          )
                      )
                  )
              )
          ));
      }
  }
  </code></pre>
  
  <p>This still gives me back all the records in 'A', and if it's related 'E' records don't satisfy the condition, then I just get this:</p>
  
  <pre><code>Array(
      [0] =&gt; array(
          [A] =&gt; array(
              [field1] =&gt; // stuff
              [field2] =&gt; // more stuff
              // ...etc
          ),
          [B] =&gt; array(
              [field1] =&gt; // stuff
              [field2] =&gt; // more stuff
              // ...etc
          ),
          [C] =&gt; array(
              [field1] =&gt; // stuff
              [field2] =&gt; // more stuff
              // ...etc
          ),
          [D] =&gt; array(
              [field1] =&gt; // stuff
              [field2] =&gt; // more stuff
              // ...etc
          ),
          [E] =&gt; array( 
              // empty if 'E.myfield' != $some_value'
          )
      ),
      [1] =&gt; array( // ...etc )
  )
  </code></pre>
  
  <p>When If 'E.myfield' != $some_value, I don't want the record returned at all.</p>
  
  <p>I hope this expresses my problem clearly enough...</p>
  
  <p>Basically, I want the following query, but in a database-agnostic/CakePHP-y kind of way:</p>
  
  <pre><code>SELECT * 
  FROM A INNER JOIN
          (B INNER JOIN 
              (C INNER JOIN 
                  (D INNER JOIN 
                      E ON D.id=E.d_id) 
                  ON C.id=D.c_id) 
              ON B.id=C.b_id) 
          ON A.id=B.a_id 
      WHERE E.myfield = $some_value
  </code></pre>