title: Joins in Cake PHP
body: <p>There are 2 models in my application associated with hasMany relationship. Model <strong>Class hasMany Session</strong> and classes can happen in multiple cities and they can also be published or unpublished. City information (city_id) is stored in Class table however the class timings are stored in session table since a class can have many sessions.</p>
  
  <p>Now, I want to list all the classes which are,</p>
  
  <ul>
  <li>active </li>
  <li>taking place in a particular city </li>
  <li>class start time is > NOW</li>
  </ul>
  
  <p>Not that class can have multiple sessions so we just want to list class once (not for every session). I am using a join as per cake tutorial but I am not good at SQL so it's not working and I am sure I am not doing something correctly. Below is the code.</p>
  
  <pre><code>            $options['joins'] = array(
                  array(
                      'table' =&gt; 'sessions',
                      'alias' =&gt; 'Session',
                      'type' =&gt; 'left',
                      'conditions' =&gt; array(
                              'Class.city_id' =&gt; $this-&gt;data['Class']['city_id'],
                              'Class.state' =&gt; 'active',
                              'Session.start &gt;= ' =&gt; date('Y-m-d H:i:s'),
                              'Class.id' =&gt; 'Session.class_id'
                          )
                  )
              );
              $classes = $this-&gt;Class-&gt;find('all', $options);
  </code></pre>
  
  <p>This code is returning all classes from all cities even though which took place in past. Can someone help me out so it returns correct classes as per the criteria mentioned above.</p>