title: How do I join two tables in a third n..n (hasAndBelongsToMany) relationship in CakePHP?
body: <p>I have a <code>n...n</code> structure for two tables, <strong><code>makes</code></strong> and <strong><code>models</code></strong>. So far no problem.</p>
  
  <p>In a third table (<strong><code>products</code></strong>) like:</p>
  
  <pre><code>id
  make_id
  model_id
  ...
  </code></pre>
  
  <p>My problem is creating a view for products of one specifi <strong><code>make</code></strong> inside my <code>ProductsController</code> containing just that's make models:</p>
  
  <p>I thought this could work:</p>
  
  <pre><code>var $uses = array('Make', 'Model');
  
  $this-&gt;Make-&gt;id = 5; // My Make
  
  $this-&gt;Make-&gt;find(); // Returns only the make I want with it's Models (HABTM)
  $this-&gt;Model-&gt;find('list'); // Returns ALL models
  $this-&gt;Make-&gt;Model-&gt;find('list'); // Returns ALL models
  </code></pre>
  
  <p>So, If I want to use the <code>list</code> to pass to my view to create radio buttons I will have to do a <code>foreach()</code> in my <strong><code>make</code></strong> array to find all models titles and create a new array and send to the view via <code>$this-&gt;set()</code>.</p>
  
  <pre><code>$makeArray = $this-&gt;Make-&gt;find();
  foreach ($makeArray['Model'] as $model) {
      $modelList[] = $model['title'];
  }
  $this-&gt;set('models', $models)
  </code></pre>
  
  <p>Is there any easier way to get that list without stressing the <strong><code>make</code></strong> Array. It will be a commom task to develops such scenarios in my application(s).</p>
  
  <p>Thanks in advance for any hint!</p>