title: CakePHP Pull data from two tables
body: <p>I have two tables in my app: 'Clients' and 'Appointments'</p>
  
  <p>In the appointments table I have a foreign key called 'clientid' which links the tables together. How would I show the appointments for that user?</p>
  
  <p>So for example when viewing a client <code>/admin/clients/view/201/</code> I would see the Client details for client 201 and also the appointments for that client.</p>
  
  <p>So far my controller looks like this:</p>
  
  <pre><code>class ClientsController extends AppController
  {
      var $name = 'Clients';
  
      function beforeFilter()
      {
          parent::beforeFilter();
          $this-&gt;Auth-&gt;allow(array('*'));  
      }
  
      function admin_view($id = null)
          {
              $this-&gt;Client-&gt;id = $id;
              $this-&gt;set('client', $this-&gt;Client-&gt;read());
          }
  </code></pre>
  
  <p>Any help would be much appreciated. Thanks</p>
  
  <p>Edit: Client model</p>
  
  <pre><code>class Client extends AppModel
  {
      var $name = 'Client';
  
      var $useTable = 'clients';
  }
  </code></pre>
  
  <p>Edit2: View</p>
  
  <pre><code>    &lt;h1&gt;&lt;?php echo $client['Client']['lastname']; ?&gt; &lt;?php echo $client['Client']['firstname']; ?&gt; (&lt;?php echo $this-&gt;Html-&gt;link('Edit', array('action' =&gt; 'edit', $client['Client']['id'])); ?&gt;)&lt;/h1&gt;
  
      &lt;p&gt;&lt;strong&gt;Date of Birth:&lt;/strong&gt; &lt;?php echo $client['Client']['dateofbirth']; ?&gt;&lt;/p&gt;
  
      &lt;h3&gt;Appointments&lt;/h3&gt;
  
  &lt;table&gt;
      &lt;?php foreach ($appointments as $appointment): ?&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;?php echo $this-&gt;Html-&gt;link($appointment['Appointment']['date'],
                  array('admin' =&gt; true, 'controller' =&gt; 'appointment', 'action' =&gt; 'view', $appointment['Appointment']['id'])); ?&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;?php endforeach; ?&gt;
  &lt;/table&gt;
  </code></pre>