title: CakePHP Containable with HABTM
body: <p>To explain the issue I'm having, I'll use an example. Let's say that I'm building a system where students can sign up for one or more afterschool courses, but a school official has to approve the sign-up in order for it to be valid. So I have these models:</p>
  
  <ul>
  <li>Course (belongs to "Teacher", hasAndBelongsToMany "Student")</li>
  <li>Student (hasAndBelongsToMany "Course")</li>
  <li>Teacher (hasMany "Course")</li>
  </ul>
  
  <p>Now let's say I want to see a list of all of the unapproved sign-ups that are for ninth-graders. That's easy:</p>
  
  <pre><code>$this-&gt;request-&gt;data = $this-&gt;Student-&gt;CoursesStudent-&gt;find('all', array(
      'conditions' =&gt; array(
          'CoursesStudent.is_approved' =&gt; null,
          'Student.grade' =&gt; 9
      )
  ));
  </code></pre>
  
  <p>The thing that I'm struggling with is pulling the teacher's data as well (more than just their ID). I've tried this:</p>
  
  <pre><code>$this-&gt;request-&gt;data = $this-&gt;Student-&gt;CoursesStudent-&gt;find('all', array(
      'conditions' =&gt; array(
          'CoursesStudent.is_approved' =&gt; null,
          'Student.grade' =&gt; 9
      ),
      'contain' =&gt; array(
          'CoursesStudent',
          'Course' =&gt; array(
              'Teacher' =&gt; array(
                  'fields' =&gt; array(
                      'Teacher.id',
                      'Teacher.name'
                  )
              )
          ),
          'Student'
      )
  ));
  </code></pre>
  
  <p>But it doesn't have any effect whatsoever on the returned array. To make it easy for you to throw this into an existing CakePHP project to play with, <a href="http://pastebin.com/11Y0C4ix" rel="nofollow">here</a> is the database schema and data and <a href="http://pastebin.com/wEBtWWyQ" rel="nofollow">here</a> is what you can paste into a random action of an existing CakePHP project. This is what I'm trying to get (notice that the teacher's data is there):</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [CoursesStudent] =&gt; Array
                  (
                      [id] =&gt; 1
                      [course_id] =&gt; 1
                      [student_id] =&gt; 1
                      [is_approved] =&gt; 
                      [created] =&gt; 2012-12-11 00:00:00
                      [modified] =&gt; 2012-12-11 00:00:00
                  )
  
              [Course] =&gt; Array
                  (
                      [id] =&gt; 1
                      [teacher_id] =&gt; 1
                      [title] =&gt; Introduction to Improvisation
                      [start_date] =&gt; 2012-12-17
                      [end_date] =&gt; 2012-12-21
                      [created] =&gt; 2012-12-11 00:00:00
                      [modified] =&gt; 2012-12-11 00:00:00
                      [Teacher] =&gt; Array
                          (
                              [id] =&gt; 1
                              [first_name] =&gt; John
                              [last_name] =&gt; Doe
                              [created] =&gt; 2012-12-11 00:00:00
                              [modified] =&gt; 2012-12-11 00:00:00
                          )
  
                  )
  
              [Student] =&gt; Array
                  (
                      [id] =&gt; 1
                      [first_name] =&gt; Bill
                      [last_name] =&gt; Brown
                      [grade] =&gt; 9
                      [created] =&gt; 2012-12-11 00:00:00
                      [modified] =&gt; 2012-12-11 00:00:00
                  )
  
          )
  
  )
  </code></pre>
  
  <p>Thanks!</p>