title: CakePHP: Using 2nd level deep model associations in a 'find' condition, returning duplicated results
body: <p>I have read numerous posts, spent hours going over the documents at cakephp.org and even tried various practical examples and I cannot seem to get this right. What I have are 3 tables as follows:</p>
  
  <ul>
  <li>projects</li>
  <li>project_tags</li>
  <li>tags</li>
  </ul>
  
  <p>When someone adds a new project, they choose their tags, which are selected from a predefined list in the tags table. This tag they entered is then stored in project_tags using the project_id and tag_id fields.</p>
  
  <p>Model relations are as follows:</p>
  
  <ul>
  <li>Project hasMany projectTag</li>
  <li>projectTag belongsTo Project</li>
  <li>ProjectTag belongsTo Tag</li>
  </ul>
  
  <p>Whether or not I have the correct relations is still trivial to me, but I have tried numerous possibilities here.</p>
  
  <p>What I am trying to do is perform a find on all projects of a specific tag. I have done this by doing the following:</p>
  
  <pre><code>$this-&gt;Project-&gt;contain(array('ProjectTag' =&gt; 'Tag', 'User' =&gt; array('id')));
  $projects = $this-&gt;Project-&gt;find('all', array('conditions' =&gt; array('ProjectTag.tag_id' =&gt; '6')));
  </code></pre>
  
  <p>The result is an SQL error that column ProjectTag.tag_id does not exist. This tells me that there is an error in the association, but where?</p>
  
  <p>Is this because I cannot use a 2nd level deep associated hasMany model in my fond condition when using containable? If so, how can I correct this?</p>
  
  <p>I know it's long, sorry. Can anyone shed some light on this bizarre situation?</p>
  
  <p>Another approach I tried was using the unbindModel() on Project, removing all the bindings to ProjectTag, and then adding a hasOne using bindModel() and a condition of ProjectTag.project_id = Project.id but this resulted on 4 records of the same project being returned, one for each ProjectTag, which does not seem right.</p>
  
  <p>I am using the containable behavior and have set recursive = -1 in the AppModel.</p>
  
  <p>Any help is greatly appreciated.
  Thanks</p>