title: CakePHP Filtering associated model by array
body: <p>I have models: Project=>Keyword</p>
  
  <p>using HMBTM relationship (set in both models).</p>
  
  <p>The keywords table acts as a Tree, ie. the keywords have hierarchical relationship amongst themselves.</p>
  
  <p>I am using containable behavior.</p>
  
  <p>A user selects a keyword.</p>
  
  <p>I want the returned records (Projects) to be limited by the selected keyword, OR any of that keyword's children.  I am trying to reuse my index action.. if no keyword is selected then render the standard index view, if keyword is selected, then find all child keywords and then filter returned projects to those with any of the keyword ids.</p>
  
  <p>I have tried creating an array of children (and original) keyword ids, but I can't work out how to get that array to become the filtering in my find action.</p>
  
  <p>I have tried using :</p>
  
  <pre><code>$this-&gt;Project-&gt;find('all',
      array(
          'contain' =&gt; array('Keyword.id'=&gt;array($childkeywords))     
      )
  );
  </code></pre>
  
  <p>where $childkeywords is an array of the relevant ids, created using array_push. But that does not use key-value pairs, just int values for each id. So I think it is not structured properly.</p>
  
  <p>I feel I want to do something quite easy, but sense I am getting further away from the solution. Is there not a standard way to limit the records to a collection of ids of an associated model?</p>
  
  <p>Cheers</p>
  
  <p>With help from Paulo, I now have:</p>
  
  <pre><code>$this-&gt;Project-&gt;find('all', array(
                                      'fields' =&gt; array('id','title','country', 'project_ref'),
                                      'type' =&gt; array('inner'),
                                      'contain' =&gt; array('Keyword' =&gt; array(
                                                                  'conditions' =&gt; array('Keyword.id' =&gt; $childkeywords)                                               
                                                                              )
                                                      )
                                              )
                                  )
  </code></pre>
  
  <p>But the use of type inner is not changing the results..</p>