title: CakePHP retrieve data, associate models, containable behavior
body: <p>I can't seem to figure out how the containable behavior works, or how to retrieve the data from (and based) on associated models.</p>
  
  <p>I need to put the following MySQL query in the cakephp find('all') function, I know i can use the query builder for the sql syntax but I want to use find function and want to figure out how it works.</p>
  
  <pre><code>SELECT events.id, events.name FROM events, user_roles
  WHERE user_roles.event_id = events.id
  AND user_roles.user_id = 1
  </code></pre>
  
  <p>The idea is simple, in the user_roles the user_id, role_id and event_id are stored. Now I want to retrieve all events for a certain user (here user_id = 1). I tried some variations on the following:</p>
  
  <pre><code>$data = $this-&gt;Event-&gt;find('all',array(
              'contain' =&gt; array(
                  'UserRole' =&gt; array(
                      'fields' =&gt; array('id'),
                      'conditions' =&gt; array(
                          'UserRole.user_id' =&gt; $this-&gt;Auth-&gt;user('id')
                      )
                  )
              )
          ));
  </code></pre>
  
  <p>But this keeps returning all events. What I want is an array like (or any other result with the same associated data):</p>
  
  <pre><code>array(
      [0] =&gt; array(
          [Event] =&gt; array(
              'id' =&gt; 1,
              'name' =&gt; 'Event Name'
          ),
          [UserRole] =&gt; array(
              'role_id' =&gt; 2,
              'event_id'=&gt; 1
          )
      [1] =&gt; array(
          .... etc ...
  )
  </code></pre>
  
  <p>The following models and associations are defined</p>
  
  <pre><code>class Event extends AppModel {
      public $hasMany = array(
          'UserRole' =&gt; array(
              'className' =&gt; 'UserRole',
              'foreignKey' =&gt; 'event_id',
              'dependent' =&gt; false,
          )
      )
  )
  
  class UserRole extends AppModel {
      public $belongsTo = array(
         'Event' =&gt; array(
              'className' =&gt; 'Event',
              'foreignKey' =&gt; 'event_id'
          ),
      )
  )
  </code></pre>
  
  <p>So how does it work ;).</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I forgot to mention that I've set in AppModel.php:</p>
  
  <pre><code>public $recursive = -1;
  </code></pre>